Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Perl pie with $1 replacements ?

by Plankton (Vicar)
on May 04, 2010 at 20:29 UTC ( [id://838377]=perlquestion: print w/replies, xml ) Need Help??

Plankton has asked for the wisdom of the Perl Monks concerning the following question:

I seem to be confused about how to use "perl -pie" from the command line. I want to use "perl -pie" at the command line to add the string "-x /tmp/ccc" to the tmpwatch command. I am trying this ...
$ /usr/bin/perl -pie 's/^(\/usr\/sbin\/tmpwatch.\*) (\d+ \/tmp)/\$1 -x + \/tmp\/ccc \$2/' /tmp/tmpwatch Can't open perl script "s/^(\/usr\/sbin\/tmpwatch.\*) (\d+ \/tmp)/\$1 +-x \/tmp\/ccc \$2/": No such file or directory. Use -S to search $PATH for it.
... but this is what happens ...
Can't open perl script "s/^(\/usr\/sbin\/tmpwatch.\*) (\d+ \/tmp)/\$1 +-x \/tmp\/ccc \$2/": No such file or directory. Use -S to search $PATH for it.
What am I doing wrong here?

Replies are listed 'Best First'.
Re: Perl pie with $1 replacements ?
by AR (Friar) on May 04, 2010 at 20:36 UTC

    I believe the "e" in "-pie" is being taken as the optional argument to -i. Try perl -pi -e instead.

      thanks! that was it!
Re: Perl pie with $1 replacements ?
by choroba (Cardinal) on May 04, 2010 at 20:36 UTC
    The -i switch demandsexpects the extension as its parameter if there is any (e in this case) (see perlrun).

    Updated.

      Nope; the extension is OPTIONAL.

      http://perldoc.perl.org/perlrun.html:

      The extension, if supplied (emphasis added), is used to....

      And though this is already discussed (below), the examples (in the 5.12 doc) of using -p, -i and -e together are constructed this way:

      perl -pi -e ...
      except where the -p is separated by a space from a -i (and I didn't find an explicit explanation of that, either).

Log In?
Username:
Password:

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

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

    No recent polls found