Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: foreach only for a section of a list

by kennethk (Abbot)
on May 04, 2012 at 15:01 UTC ( #968934=note: print w/replies, xml ) Need Help??

in reply to foreach only for a section of a list

There are a few ways. You can use C-style For Loops:

for (my $i = 0; $i < @somewords -1; $i++) { print " $somewords[$i];\n" }
You can use Slices:

foreach $core (@somewords[0 .. $#somewords-1]) { print " ${core};\n" }
Or, in some cases, it makes sense to use Loop Control:

my $i = 0; foreach my $core (@somewords) { next if ++$i == @somewords; print " ${core};\n" }


#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://968934]
[erix]: I do some work as a corrector (if that's the right word) and often I have to remove phrases that people think is dutch but that is really literally taken from english (and does not exist in dutch. Although at some point it becomes acceptable, of course)

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2018-03-19 22:20 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (246 votes). Check out past polls.