SPUG: looking for $variable for multiline print

Matt Tucker tuck at whistlingfish.net
Tue Feb 5 19:33:33 CST 2002


-- Colin Meyer <cmeyer at helvella.org> spake thusly:

> On Tue, Feb 05, 2002 at 12:37:46PM -0800, Matt Tucker wrote:
>> -- Tim Maher <tim at consultix-inc.com> spake thusly:
>> > 
>> > I think you want: 
>> > 	$context="";
>> > 	if (/begin_pat/ .. /end_pat/) { $context .= "$_\n" }
>> > 	print $context;
> 
>> 
>> Alternately, you might be wanting to do something like:
>> 
>> if ( /(begin_pat .. end_pat)/s ) {
>>     print $1;
>> }
> 
> Matt's suggestion will do something very different from Tim's. The two
> characters '..' have very different meanings inside and outside of a
> regular expression. Outside they are [in scalar context] the
> 'flip-flop' operator [see perldoc perlop]. Inside they are two
> separate "wildcard" metacharacters.
> 
> I really like the flip-flop operator.  It reminds me of learning
> boolean logic by wiring together nand gates.  It's also incredibly
> useful in one liners:
>   # print out the contents of <foo> </foo> tags:
>   pyx file.xml |perl -ne'print if /^\(foo/../^\)foo/' |pyxw

Keep in mind that I wasn't intending to use the '..' construction
literally inside the regex. I probably should've said something like
'.*?' to make it clearer, though.
-------------- 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/17cb59ba/attachment.bin


More information about the spug-list mailing list