SPUG: looking for $variable for multiline print
Colin Meyer
cmeyer at helvella.org
Tue Feb 5 18:15:09 CST 2002
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
Have fun,
-C.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org
More information about the spug-list
mailing list