Menu{Master,Maestro,etc} question(s)

Fairlight fairlite at fairlite.com
Tue May 8 20:40:05 PDT 2007


Confusious (Jay Ashworth) say:
> > *skips*  :)
> 
> Yup; that was mostly for you.
> 
> :-P

I figured.  :)

> > > # the regex ahead is:
> > > #
> > > # label:if:var="contents"  :
> > > # ''''','','''','''''''','',
> > > # \1    \2 \3   \4       \5
> > > 
> > > perl -pi.bak -e "
> > >         if (/^$2:/)
> > >           s/([^:]):([^:]):([^\"])\"([^\"])\"([^:]):/\1:\2:\3\"$3\"\5:/;" $1
[...]
> I'm trying to replace the contents of the single pair of double quotes
> in between second and third colons.  See the example, with the commas
> and apostrophes for delineation, and the backreferences below, above?
> 
> Oh, and only on the line starting with the label noted, which is the
> part I'm least confident about.

Oy.  Could you make it harder on yourself? :) If all you need to do is
replace the contents of the doublequotes in the last segment, and you're
not checking what var or any of the other stuff except the label actually
is, you want this:

perl -pi.bak -e '$line = shift; $sub = shift; while (<>) {if ($_ =~ /^${line}:/)
{s/^(.+:[^:]+")[^"]+(".*)/$1${sub}$2/;}print;}' $2 $3 $1

This takes the first two arguments after the "program" out of the argument
list and into variables.  What's left is the filename, used in the <>
special diamond, which basically reads all lines from any files named on
the commandline (or STDIN if there are none)--all that's left after the
shifts -is- $1, which is your filename.

On each line in the while loop, it reads from that file, tries to match
labels, and if it does, substitutes using only 2 backrefs and the actual
substitution.  Everything before the doublequote (inclusive) is preserved,
everything after the second doublequote (inclusive) is preserved.  Only
the contents between are replaced.  It prints each line it took in,
substitution where appropriate, else unchanged.

Tested.

mark->


More information about the Filepro-list mailing list