in reply to Finding part of a file

Hi,

I would suggest to play around with the $/ variable (i.e. line seperator). You can do it like this.

use strict; use warnings; { local $/=""; <DATA> =~ /banana\n(.*)\ngrape\n/s; print $1; } __DATA__ apple banana pear peach grape orange

The local is not needed in this case, but it is a good habit to use it since you are resetting perl internal variables.
This prints

pear
peach

I hope this helps,
---------------------------
Dr. Mark Ceulemans
Senior Consultant
IT Masters, Belgium

Replies are listed 'Best First'.
Re: Re: Finding part of a file
by strat (Canon) on Dec 04, 2001 at 18:28 UTC
    At Mr. Ceulemans reply, I'd like to show up a different way, without the use of $1:
    { local $/ = undef; my ($foundString) = ( <DATA> =~ /\bbanana\n(.*)\ngrape\n/s ); print $foundString; } __DATA__ apple banana pear peach grape orange
    The problem with this code might be multivalued lines (because of \b)... Best regards, Strat