Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: foreach only for a section of a list

by Lotus1 (Curate)
on May 04, 2012 at 15:20 UTC ( #968941=note: print w/replies, xml ) Need Help??


in reply to foreach only for a section of a list

Here are two other ideas: you can store and print the previous value each iteration or you can pop the final element off the array then use foreach on the remaining elements.

use strict; use warnings; my @somewords = qw(a b c d); my $previous_core = ''; foreach my $core (@somewords) { print "$previous_core\n" if $previous_core ne ''; $previous_core=$core; } print "************\n"; my $popword = pop @somewords; print "popped >${popword}<\n"; print "\@somewords:\n"; print "$_\n" foreach @somewords; print "************\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://968941]
help
Chatterbox?
[Lady_Aleena]: The people I'm talking with think /$var/ looks weird with some saying it shouldn't work.
[LanX]: interpolation! like in a "string"

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2017-04-28 09:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (520 votes). Check out past polls.