in reply to Extract Multiple Lines from the End of a multi-line string

Got Perl v5.8.0+ ?
sub Last_N_Lines { my ($String, $N) = @_; my @ret; open(my $IN, "<", \$String); while (<$IN>) { push(@ret, $_); shift(@ret) if $. > $N } return join "", @ret; }

Updated: Thanks, ikegami!

Replies are listed 'Best First'.
Re^2: Extract Multiple Lines from the End of a multi-line string
by ikegami (Patriarch) on Oct 17, 2008 at 16:56 UTC
    That doesn't print the last N lines. That prints lines [N+1 .. last]