here's more of my 2 cents (have fun Uri! :)<br>
<br>
I notice there's two examples of for, but no examples of multiple lexical (my) variable assignments in for.<br>
<br>
for ($i = 1, $j = 6; $i < 10; $i++, $j++) {<br><br>
and<br>
<br>
for (my $i = 1; $i < 10; $i++) {<br>
<br>
Normally multiple lexical variables are declared in the same line like<br>
<br>
my ($i, $j);<br>
<br>
But if you do that you can't initialize them. my ($i=1, $j=2); gives an error. this works ...<br>
<br>
my $i=1;<br>
my $j=2;<br>
<br>
this is the common way. but ...<br>
<br>
my ($i, $j) = (1,2);<br>
<br>
is another way.<br>
<br>
here's another way, in a for statement:<br>
<br>
for (my $i=1, my $j=6; $i < 10; $i++, $j++) { print "$i\n" }<br>
<br>
and so,<br>
<br>
my $i=1, my $j=2;<br>
<br>
works too.<br>
<br>
even more thrilling is<br>
<br>
my $k = (my $i=1, my $j=2);<br>
<br>
which gives $k a 2.<br>
<br>
<br>
<br>
<div><span class="gmail_quote">On 4/13/07, <b class="gmail_sendername">Liam R E Quin</b> <<a href="mailto:liam@holoweb.net">liam@holoweb.net</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;">
On Thu, 2007-04-12 at 11:21 -0400, Uri Guttman wrote:<br><br>> useful? that is what it is designed for. it was taken from c which has<br>> the same operator but no list context to confuse things.<br><br>The , in C that's used in parameter lists (for example), as in
<br> int m = max(3, 12, 9, 76);<br>is like the comma in a Perl list,<br> my $m = max(3, 12, 9, 76);<br>which is not at all like<br> my @mm = max(3, 12, 9, 76);<br>:-)<br><br>Similarly, the C comma operator, really only used in a few
<br>places these days because it's dangerous otherwise, is the same<br>as semicolon except that it doesn't terminate the statement, so<br><br> if (e) a = 3,<br> b = 6,<br> c = 12;<br><br>is the same as<br>
<br> if (e) {<br> a = 3;<br> b = 6;<br> c = 12;<br> }<br><br>except harder to follow. In Perl, you have to use the braces, so the<br>second form is enforced, but you can still do things like<br>
<br>for ($i = 1, $j = 6; $i < 10; $i++, $j++) {<br> stuff<br>}<br><br>and that's also the main place the comma operator is used in C.<br><br>I'd prefer in most cases<br>for (my $i = 1; $i < 10; $i++) {<br>
my $j = $i + 5;<br> stuff;<br>}<br><br>because the relationship between in and j is now made explicit.<br><br>Liam<br><br>--<br>Liam Quin - XML Activity Lead, W3C, <a href="http://www.w3.org/People/Quin/">http://www.w3.org/People/Quin/
</a><br>Pictures from old books: <a href="http://fromoldbooks.org/">http://fromoldbooks.org/</a><br>Ankh: <a href="http://irc.sorcery.net">irc.sorcery.net</a> <a href="http://irc.gnome.org">irc.gnome.org</a> <a href="http://www.advogato.org">
www.advogato.org</a><br><br></blockquote></div><br>