Help for this page

Select Code to Download


  1. or download this
    sub Last_N_Lines {
       my($String, $N) = @_;
       my $re = '^' . ( '.*\\n' x ($N-1) ) . '(?:.*\\n|.+)';
       return ( $String =~ /($re)\z/ )[0];
    }
    
  2. or download this
    sub Last_N_Lines {
       my($String, $N) = @_;
       --$N;
       return ( $String =~ /^( (?:.*\n){$N} (?:.*\n|.+) )\z/mx )[0];
    }