[tpm] dereferencing anonymous hashes
Liam R E Quin
liam at holoweb.net
Fri Apr 13 12:16:55 PDT 2007
On Thu, 2007-04-12 at 11:21 -0400, Uri Guttman wrote:
> useful? that is what it is designed for. it was taken from c which has
> the same operator but no list context to confuse things.
The , in C that's used in parameter lists (for example), as in
int m = max(3, 12, 9, 76);
is like the comma in a Perl list,
my $m = max(3, 12, 9, 76);
which is not at all like
my @mm = max(3, 12, 9, 76);
:-)
Similarly, the C comma operator, really only used in a few
places these days because it's dangerous otherwise, is the same
as semicolon except that it doesn't terminate the statement, so
if (e) a = 3,
b = 6,
c = 12;
is the same as
if (e) {
a = 3;
b = 6;
c = 12;
}
except harder to follow. In Perl, you have to use the braces, so the
second form is enforced, but you can still do things like
for ($i = 1, $j = 6; $i < 10; $i++, $j++) {
stuff
}
and that's also the main place the comma operator is used in C.
I'd prefer in most cases
for (my $i = 1; $i < 10; $i++) {
my $j = $i + 5;
stuff;
}
because the relationship between in and j is now made explicit.
Liam
--
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org www.advogato.org
More information about the toronto-pm
mailing list