Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Perl command line search and replace

by dynamo (Chaplain)
on Jan 05, 2008 at 03:57 UTC ( [id://660501]=note: print w/replies, xml ) Need Help??


in reply to Perl command line search and replace

imo, if you want to run it as a cron job, it's worth making it into a script so that you don't have to lose one of your two main quoting mechanisms in just writing the program.

Also, you will have to be aware of shell-based quoting and interpolation rules as a first layer of evaluation before your perl program gets to it. For example if you had a variable called $HOSTNAME, it would not start out undefined on unix systems. It wouldn't even get to perl still being a variable - unless you start backslashing(cancelling) the $. Basically all $s. And if you want to print one, you start to have to worry about whether you want to backslash the backslash that comes before the backslashed $ (you do, IIRC.)

Unless you take pleasure in excessive unnecessary complication (a common affliction in these halls, I know,) I say write a short script if at all possible, and just call it from cron. This way you can use the full range of quoting mechanisms the shell offers you to express your search and replace terms.

- d

  • Comment on Re: Perl command line search and replace

Replies are listed 'Best First'.
Re^2: Perl command line search and replace
by quester (Vicar) on Jan 05, 2008 at 08:09 UTC
    Actually, if the system shell is sh or bash, the extreme problem with every $ variable in the perl script needing to be backslashed as \$ only applies if the script is in double quotes. A single quoted script will be passed intact to perl, needing backslashes only in front of single quotes.

    For instance, the nasty

    perl -wle "\$x=42; print \$x"
    can be written as a fairly tolerable
    perl -wle '$x=42; print $x'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://660501]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 19:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found