Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: handle special character in filename

by moritz (Cardinal)
on Oct 17, 2012 at 10:59 UTC ( #999521=note: print w/ replies, xml ) Need Help??


in reply to handle special character in filename

You can use the LIST form of system, which avoids the need to escape the arguments.

But of course you can do search-and-replace in Perl too, no need to shell out for that.


Comment on Re: handle special character in filename
Re^2: handle special character in filename
by Anonymous Monk on Oct 17, 2012 at 11:36 UTC
    I did not get it.Could you please explain how to modify in this sed command.

      system("sed","-i","s/$org/$rep/g", $file);

      By the way, you can use Tie::File and \Q..\E constructs inside native Perl regexps (instead of sed), thus not having to run sed (which costs you another fork() and some rename operations) and being able to replace any strings containing any special sharacters.

      Sorry if my advice was wrong.
Re^2: handle special character in filename
by BillKSmith (Chaplain) on Oct 17, 2012 at 21:04 UTC

    The list form may work in this case, but I doubt that it will if the special character is a space. I have been unable to truly solve a similiar problem where system does not correctly parse a command that includes filenames that contain spaces.

    Bill

      Hello

      I have test system $command,@params with sed and a file with space in its filename, and it works (at least in Debian)

      $ echo "pa" > "a b" $ cat p system ("sed","s,a,o,","a b"); $ perl p po

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (12)
As of 2014-12-26 12:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls