Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: foreach loops

by zentara (Archbishop)
on Oct 08, 2006 at 13:00 UTC ( [id://576989]=note: print w/replies, xml ) Need Help??


in reply to foreach loops

Just for the sake of fun, if you switch to a while loop
#!/usr/bin/perl use warnings; use strict; my @names = ('rita', 'sue','bob', 'daisy'); while (@names){ my $name1 = shift @names; my $name2 = shift @names; if( defined $name2){ print "$name1 $name2\n"; unshift @names, $name2; }else{ print "$name1\n";} }

Output:

rita sue sue bob bob daisy daisy

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-19 04:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found