in reply to Inserting into an array while stepping through it
or if you only want to operate on multiples of five:my @list = ( 5, 11, 7); my @timesthree = map { $_ *= 3 } (@list);
BUT, you will get a list of one item! so you want:my @timesthree_onlyfives = map { $_ *= 3 if ($_ % 5 == 0) } (@list);
But that could be done better.my @all_timesthree_onlyfives = map { if ($_ % 5 ==0) { $_ *= 5; } else { return $_; } } (@list);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Inserting into an array while stepping through it
by sauoq (Abbot) on Jun 13, 2003 at 02:43 UTC | |
by meredith (Friar) on Jun 13, 2003 at 02:52 UTC |