Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

for[each]

by Adam (Vicar)
on May 09, 2000 at 00:22 UTC ( [id://10661]=note: print w/replies, xml ) Need Help??


in reply to My favorite looping mechanism in Perl is:

for and foreach are synonymous. You can use either to do the same thing.

Replies are listed 'Best First'.
RE: foreach
by BBQ (Curate) on May 09, 2000 at 03:18 UTC
    Yeah, but foreach is so much more cuddly! Don't you just want to hug it and never let go? I could never go back to for.
      You're scaring me, John. :)
        Naw, I agree with the BBQ-- foreach has a thick, soft coat, like a sheepdog (but smells better-- maybe more like a Gund Sheepdog.)

        For that matter, goto is sharp-edged and rusty. they only people who touch goto are those ultra-macho pantywaists who were big belt buckles and dropping handlebar mustaches without irony.

        Hehe, sorry Adam! :o)

        On the risk of sounding totally un-PC, my remark was a bit too gay, wasn't it? God, I need a girlfriend...

        #!/home/bbq/bin/perl
        # Trust no1!
RE: foreach
by guice (Scribe) on May 15, 2000 at 08:58 UTC
    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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-24 23:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found