throop has asked for the wisdom of the Perl Monks concerning the following question:
"That won't work," I thought. "It should be:"my $text; for $text(@array){ $hash->{$text}++}
But investigation showed that it worked fine. Further,my $text; foreach $text(@array){ $hash->{$text}++}
printed out barbazne.my @foo = qw(bar baz ne); foreach (my $ix=0;$ix < @foo; $ix++){print $foo[$ix]}
So it looks like for and foreach will accept each others' formats. Are they in fact equivalent? Or is code that exploits this vulnerable to subtle bugs?
thanks
throop
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Risks of equivalence between FOR and FOREACH
by ikegami (Patriarch) on Oct 31, 2006 at 22:09 UTC | |
by blazar (Canon) on Oct 31, 2006 at 23:10 UTC | |
|
Re: Risks of equivalence between FOR and FOREACH
by jeffa (Bishop) on Oct 31, 2006 at 21:54 UTC | |
|
Re: Risks of equivalence between FOR and FOREACH
by imp (Priest) on Oct 31, 2006 at 21:55 UTC | |
|
Re: Risks of equivalence between FOR and FOREACH
by Fletch (Bishop) on Oct 31, 2006 at 21:55 UTC |