Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

RE: foreach

by guice (Scribe)
on May 15, 2000 at 08:58 UTC ( #11559=note: print w/ replies, xml ) Need Help??


in reply to for[each]
in thread My favorite looping mechanism in Perl is:

Well, 'for' and 'foreach' may be the same, but I never use them for it. I use 'foreach' to step through arrays/lists, and I use a 'for' for pattern switching:

for ($var) { /test/i && do { # stuff here last; }; do { # nice default last; # not really needed here .. But what the hey :) }; }
You can lable it SWITCH and say last SWITCH .. You can even use 'break' instead of 'last' (If I remember right) .. Either way, it works like the C/C++ switch with better matching abilities :) 'foreach' and 'while' do all my loops and walk throughs. 'map' and 'grep' are used for quickly one liners, or two, depening on what I want done ...

The right function for the job. I just don't have use for the formal 'for' loop. Too many things are far better and faster in Perl. Leave 'for(;;;)' for C(++)?, Pascal and (Q|R|V)?Basic.;P

-- philip
Never underestimate the power of very stupid people in large groups.


Comment on RE: foreach
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11559]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2015-07-05 16:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls