I guess I've just never seen $x = (); before. doesn't seem very useful unless it's a list expression.<br>
<br>
[robj@localhost ~]$ perl -e '$x=(5,44); print "$x\n";'<br>
44<br>
<br>
[robj@localhost ~]$ perl -e '$x=@x=(5,44); print "$x\n";'<br>
2<br>
<br>
So the comma operator behaves differently in a scalar context from how it behaves in a list context.<br>
<br>
[robj@localhost ~]$ perl -e 'sub x { print "side effect\n"; return 5 } $x=(x,44); print "$x\n";'<br>
side effect<br>
44<br>
<br>
Showing that the comma operator is useful for side effects in scalar context mode.<br>
<br>
<br>
<div><span class="gmail_quote">On 4/10/07, <b class="gmail_sendername">Uri Guttman</b> <<a href="mailto:uri@stemsystems.com">uri@stemsystems.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
>>>>> "RJ" == Rob Janes <<a href="mailto:janes.rob@gmail.com">janes.rob@gmail.com</a>> writes:<br><br> RJ> $x = (); is a list assignment to a scalar. scalar conversion<br> RJ> results in the scalar ($x that is) being assigned the count of the
<br> RJ> number of items in the list. 0 or zero.<br><br>wrong result and wrong explanation. you can't have a list in scalar<br>context by definition. in this case the () are just doing grouping of<br>nothing so it is just like saying my $x and the value in $x is undef.
<br><br>perl -lwe '$x = () ; print $x'<br>Use of uninitialized value in print at -e line 1.<br><br>you can only get the number of elements in an array by putting it in<br>scalar context. and () does not make a list. parens only do grouping in
<br>perl, and never directly make a list.<br><br>uri<br><br>--<br>Uri Guttman ------ <a href="mailto:uri@stemsystems.com">uri@stemsystems.com</a> -------- <a href="http://www.stemsystems.com">http://www.stemsystems.com
</a><br>--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-<br>Search or Offer Perl Jobs ---------------------------- <a href="http://jobs.perl.org">http://jobs.perl.org</a><br></blockquote></div>
<br>