Perl Monk, Perl Meditation | |
PerlMonks |
Re: For and foreach...by salvadors (Pilgrim) |
on Jan 20, 2001 at 21:28 UTC ( [id://53233]=note: print w/replies, xml ) | Need Help?? |
Perl has these two statements for a reason and they are appropriate each in different cases ... is done far more easily (and efficiently?) with foreach. No, no, no. For and foreach are identical. Yes, they're there for a reason, but that's not because they do anything different, or because one is better at one thing, or anything like that. Perl as a language grew out of linguistic principles. Larry describes Perl as a diagonal language rather than an orthogonal one. It has no problem having more than one command that does exactly the same thing, just as most natural languages have words that mean exactly the same thing. The two different versions of for make it easier to read Perl in English. You can quite happily, to take your examples, write: and and perl will Do The Right Thing(tm). In fact it will Do The Same Thing. But many people will find it easier to read them the original way. Which is important in the Perl World. Tony
In Section
Seekers of Perl Wisdom
|
|