in reply to Re^2: Extract Multiple Lines from the End of a multi-line string
in thread Extract Multiple Lines from the End of a multi-line string

Oops, missed the second question.

and also the [0] on the end of the return?

In list context, the match operator returns what it captured. I used a list slice to force list context.

$x = 'abc' =~ /a(.)c/; # 1 (or false on fail) @x = 'abc' =~ /a(.)c/; # b (or () on fail) $x = ( 'abc' =~ /a(.)c/ )[0]; # b (or undef on fail)
I could also have used
$x = 'abc' =~ /a(.)c/ && $1; # b (or false on fail)

Replies are listed 'Best First'.
Re^4: Extract Multiple Lines from the End of a multi-line string
by NateTut (Deacon) on Oct 17, 2008 at 16:15 UTC
    Thanks for the explanation. I was trying to do something like (.*\n){5} and was getting nowhere.
      Presumably followed by \z? Your last line doesn't end with \n, and that's a bad use of capturing parens.
        Yes it was followed by /z. Why is that bad use of capturing parens?