--- Chas Owens <[EMAIL PROTECTED]> wrote:
> On 4/19/07, John W. Krahn <[EMAIL PROTECTED]> wrote:
> > Chas Owens wrote:
> > > Yes, foreach was aliased to for for backwards
> compatibility,
> >
> > Huh? Do you have something to back up that claim?
>
> Well, perlsyn* says
> The "foreach" keyword is actually a synonym
> for the "for" keyword, so
> you can use "foreach" for readability or
> "for" for brevity. (Or
> because the Bourne shell is more familiar to
> you than csh, so writing
> "for" comes more naturally.)
>
> But Synopsis 4* says
> There is no foreach statement any more. It's
> always spelled for
> in Perl 6,
> so it always takes a list as an argument
>
> So, you can either start training yourself to say
> for instead of
> foreach now or wait for culture shock down the road.
>
It really does not matter to me which one I use b/c
they both work well and seem to produce the same
results in all my tested code. Its like asking me
would you like that coffee with cream/sugar or black.
ANSWER: I like coffee black and with cream/sugar, it
does not matter much and it all depends upon my mood.
Interesting though I ran perl -MO=Deparse on this
code...
[EMAIL PROTECTED] /cygdrive/c/temp
$ cat foo1
for my $i (0 .. 3) {
$i *= 3;
print $i,"\n";
}
print "\n\n";
for my $i (map { $_ * 3 } 0 .. 3) {
print "$i\n";
}
$ perl -MO=Deparse foo1
foreach my $i (0 .. 3) {
$i *= 3;
print $i, "\n";
}
print "\n\n";
foreach my $i (map {$_ * 3;} 0..3) {
print "$i\n";
}
foo1 syntax OK
So is foreach really dead or going away?
BTW Great write up Chas!
$ perl -v
This is perl, v5.8.7 built for
cygwin-thread-multi-64int
(with 1 registered patch, see perl -V for more detail)
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/