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

Bill Campbell bill at celestial.com
Mon May 14 13:09:38 PDT 2007


On Mon, May 14, 2007, Jay R. Ashworth wrote:
>On Mon, May 14, 2007 at 02:56:09PM -0400, Jay R. Ashworth wrote:
>> I actually ended up with:
>> 
>> perl -pi.bak -e 'BEGIN {$label=shift; $sub=shift;}
>>         if (/^$label:/)
>> 		s/^(.+:[^:]+")[^"]+(".*)/$1${sub}$2/;' $2 $3 $1
>> 
>> You forgot the if clause.  The trailing semicolon, too, in the -e, but
>> I suspect that's optional.
>> 
>> Testing now.
>
>And teh answer is:
>
>MsUs-1:/appl/filepro/dddtmp # mmreplace ./prc.jra tstdate replacement
>syntax error at -e line 3, near ")
>    s/^(.+:[^:]+")[^"]+(".*)/$1${sub}$2/"
>Execution of -e aborted due to compilation errors.
>
>I *thought* it might be the unescapedness of those double quotes, but
>quoting them doesn't change the error message.

One of the things I really like in perl, that's not in python, is
the concept of alternative methods of quoting which can make
things like this much cleaner.

Single quotes, 'stuf' can be replaced with q(stuf).

Double auotes, "stuf$variable" by qq(stuf$variable).

Backticks `somecommand` by qx(somecomand).

Regular expressions /expression/ by qr(expression).

This is particularly useful when the stuff you want quoted
contains the character you need to use for the quotes.

Furthermore, the quoted text can be enclosed in parenthesis,
braces, etc., so that vi(m)'s ``%'' key can be used to find the
matching delimiter (this is very high on my list of priorities).

Bill
--
INTERNET:   bill at Celestial.COM  Bill Campbell; Celestial Software, LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
FAX:            (206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676

Government's view of the economy could be summed up in a few short phrases:
If it moves, tax it.  If it keeps moving, regulate it.  And if it stops
moving, subsidize it -- Ronald Reagan


More information about the Filepro-list mailing list