in reply to Extracting numbers from arrays
Maybe a use for grep. Set $first and $last to the two numbers you're looking for.
my $flag; my @new = grep { $flag = 1 if $_ == $first; $flag = 0 if $_ == $last; $flag } @old;
Of course, this breaks if you have multiple occurances of your target numbers.
Update: Abigail-II is right of course. The flip-flop operator (..) does exactly what I wanted. Shame it dropped out of my head temporarily as I was writing this reply :(
--"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extracting numbers from arrays
by Abigail-II (Bishop) on Jun 30, 2003 at 13:55 UTC |