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

Jay R. Ashworth jra at baylink.com
Thu May 10 06:34:00 PDT 2007


On Tue, May 08, 2007 at 11:40:05PM -0400, Fairlight wrote:
> > > > 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

Oh, sure; cause that's *obviously* clearer. 

:-)

> 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.

I see what you've done... but it's very close to More Proof that perl
is a write-only language. :-)  I saw your folo, too, but I figured I'd
comment here, since the extra <> loop clouds the issue -- and therefore
makes my point -- even better. 

I'll likely run your version, though.  Thanks.

Cheers,
-- jra
-- 
Jay R. Ashworth                                                jra at baylink.com
Designer                          Baylink                             RFC 2100
Ashworth & Associates        The Things I Think                        '87 e24
St Petersburg FL USA      http://baylink.pitas.com             +1 727 647 1274


More information about the Filepro-list mailing list