Re^3: Hard syntax error or disambiguable parsing?
by merlyn (Sage) on Jan 29, 2009 at 05:08 UTC
|
Sure, the words are interchangable, in the same way that you can omit $_ a lot. It's not as clear, and this is clearly a beginner, so I thought I'd bring clarity back.
As for the second statement, I don't understand your complaint. The first loop does indeed create a new local scalar variable, as I said.
| [reply] |
|
|
| [reply] [d/l] [select] |
|
|
my $i = 5;
for $i (10..15) { }
print "$i\n";
prints 5. So clearly, the $i being iterated is not the $i from the my immediately above it.
A scalar member of an array is not a simple scalar. By Larry's rule, it has to be a simple scalar.
| [reply] [d/l] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| [reply] |
|
|
|
|
|
|
|
|
|
|
I for one applaud your statement about clarity!
I see a lot of code on Monks that uses obscure
features of Perl when they aren't necessary. I also see a massive fascination with
$#list. I don't understand why that is! The scalar value of @list does everything I need. One of the magic
things about Perl is the ability to iterate over a list without knowing
or caring about the "last index" or how many things are even in the list!
I always use foreach(@list){} instead of for(@list){}.
A "C" style "for loop" is a rare duck in Perl (although seldom doesn't mean never).
Even though "for" and "foreach" are equivalent in this case, foreach my $variable (@list){} is more
clear. HORRAY!
| [reply] |