SPUG: looking for $variable for multiline print

Matt Tucker tuck at whistlingfish.net
Tue Feb 5 14:37:46 CST 2002

-- Tim Maher <tim at consultix-inc.com> spake thusly:

> On Tue, Feb 05, 2002 at 08:51:31AM -0800, Bob Brockhausen wrote:
>> Does anyone know which $var to set to print
>> out more than one line when matching?? I can't 
> There ain't no such thing! 8-}
>> remember nor find it in Camel book...
>> I tried to 
> 	if (/being_pat/ .. /end_pat/) { print "$_\n"}
> I think you want: 
> 	$context="";
> 	if (/begin_pat/ .. /end_pat/) { $context .= "$_\n" }
> 	print $context;
> The only variable that I can think of that's relevant is the one
> allowing you to read/match/print entire paragraphs at a time: $/="".
> But that's appropriate for printing entire paragraphs that contain a
> match, not for printing all lines within a range of matching patterns,
> as you've shown above.

Alternately, you might be wanting to do something like:

if ( /(begin_pat .. end_pat)/s ) {
    print $1;

Adding the 's' will cause perl to match across multiple lines, but
you've got to make sure you've read in multiple lines as well (perhaps
by undef'ing $/ or setting it to '').
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
Url : http://mail.pm.org/archives/spug-list/attachments/20020205/d1b6c5b7/attachment.bin

More information about the spug-list mailing list