Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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 (Priest) 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]
[msh210]: perl -e'warn "test$/", "" '
[msh210]: doesn't append anything.
[msh210]: It should say "If the last nonempty element of LIST" or "If the string thus to be printed does not end in a newline""
[msh210]: Am I wrong?
[shmem]: no. You're right.
[msh210]: About time... last time I was right was... I don't even remember when.
[shmem]: perl -e 'warn "test$/", ^@^ '
[Eily]: well, at least it's right about warn doing the same thing as die :)
[shmem]: same with undef as last element
[msh210]: oh, good point. It's the best kind of correct

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (19)
As of 2017-04-24 12:41 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (439 votes). Check out past polls.