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

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

Replies are listed 'Best First'.
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 (Vicar) 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.



      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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://999521]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2018-01-19 22:05 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (223 votes). Check out past polls.