Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: foreach only for a section of a list

by lune (Pilgrim)
on May 04, 2012 at 15:02 UTC ( #968936=note: print w/replies, xml ) Need Help??


in reply to foreach only for a section of a list

One possibility is to only iterate over the elements of the array you need, using a slice:
use strict; my @somewords = ("a", "b", "c"); foreach my $core (@somewords[0..$#somewords-1]) { print "${core};\n"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://968936]
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 2022-05-21 22:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (78 votes). Check out past polls.

    Notices?