Perl monking (was Menu{Master,Maestro,etc} question(s)

Fairlight fairlite at fairlite.com
Thu May 10 07:36:28 PDT 2007


Four score and seven years--eh, screw that!
At about Thu, May 10, 2007 at 09:57:46AM -0400,
Jay Ashworth blabbed on about:
> I read it as "if you use -i, then your -e commands will be used as the
> target of 
> 
> while (<>) {};"
> 
> IE: it automagically does all the context for you, like awk, and all
> you have to do it write the body of the loop.  I'm gonna test it in
> about 10 minutes, so I'll know.  The only thing that might be a problem
> is that in -i mode, there may be no way to get the shifts *out* of the
> loop, which would, I think, be fatal.

Upon scrolling down the perlrun manpage, I see you're correct based on
the examples given--also upon reading the docs on -p in the same page.
My mistake for skimming yesterday.  In that event:

perl -pi.bak -e 'BEGIN {$line=shift; $sub=shift;} s/^(.+:[^:]+")[^"]+(".*)/$1${sub}$2/' $2 $3 $1

This is untested, but based on the -p documentation.  Specifically:

"BEGIN and END blocks may be used to capture control
 before or after the implicit loop, just as in awk."

In theory, this should work fine, since that magic operator in the implicit
loop from -p is only hit -after- BEGIN is done with things, at which point
@ARGV has already been modified to only contain the filename in question.

mark->
-- 
No matter what your problems, modern medicine can help!
http://members.iglou.com/fairlite/fixital/


More information about the Filepro-list mailing list