Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Command-line arguments to command-line Perl

by BrowserUk (Pope)
on Oct 04, 2010 at 00:57 UTC ( #863218=note: print w/ replies, xml ) Need Help??


in reply to Command-line arguments to command-line Perl

Take a look at Perl's -s option.

Ignoring any quoting issues, something like this should work:

perl -pi -se 's/.*'def'.*''/\t"def" => "dumper\/$D.def",/g' -D=ADCIF C +onfigFile

Note: That -D=... becomes $D inside the script.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re: Command-line arguments to command-line Perl
Select or Download Code
Re^2: Command-line arguments to command-line Perl
by RecursionBane (Sexton) on Oct 04, 2010 at 05:01 UTC

    Thanks for the suggestion, BrowserUk. I wasn't able to get this to work, because perl seemed to think that the argument was meant for it, rather than the script, and I ended up using suhailck's BEGIN() solution, instead.

    I do appreciate everyone's time and effort in helping me understand one of Perl's lesser-known functionalities! Thanks, everyone!

    ~RecursionBane

      I wasn't able to get this to work, because perl seemed to think that the argument was meant for it, rather than the script,

      Sorry. I don't often use -s with -e.

      You have to use -- to delineate between switches meant for perl, and those meant for the -e script:

      perl -pi -se's/.*'def'.*''/\t"def"=>"dumper\/$D.def",/g' -- -D=ADCIF C +onfigFile

      Not very practical on the command line, but useful in shell scripts.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2015-07-03 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (56 votes), past polls