in reply to Last index use in array slice
Another way to do it: instead of splitting everything and then ignoring some of it, find and split only the stuff you want.
use strict; use warnings; my $str = "discard\ndiscard\nkeep1\nkeep2"; my $discard = 2; my @arr = ($str =~ /^(?:[^\n]*\n){$discard}(.*)/s ? split /\n/, $1 : ( +) ); print "@arr";
When's the last time you used duct tape on a duct? --Larry Wall
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Last index use in array slice
by bart (Canon) on Dec 03, 2012 at 13:15 UTC | |
by ColonelPanic (Friar) on Dec 03, 2012 at 13:29 UTC |
In Section
Seekers of Perl Wisdom