Re: How to deal with "{" in system("...command..."); ?



Kuhl <chen_zhitao@xxxxxxxxx> wrote:

But there's another command which also works directly in shell, but
failed in Perl command system("..."); that is:
sed "s/ \.\.\.\.\.\.\.\./ /" file_a > file_b
I want to replace all strings of one blank followed by 8 dots
( ........) with just one blank ( ). It works correctly in the shell.

But If I try to run it in Perl like following:
system("sed 's/ \.\.\.\.\.\.\.\./ /' file_a > file_b");
then it seems \. is not interpreted as one dot, but interpreted as any
one character. So everywhere there are 8 characters following a blank,
they are all replaced.

There are some things you should try to to do debug your own programs. One
of the things to try is to print the string you think you are running, by
replacing system with print.

print("sed 's/ \.\.\.\.\.\.\.\./ /' file_a > file_b");

The output is:

sed 's/ ......../ /' file_a > file_b

The backslashes are special to perl's double-quotes, and so the backslashes
are getting eaten be perl and are not making it to sed.

You could use single quotes instead of double quotes, but those would
conflict with the literal single quotes around the sed expression. So
you can use perl's choose-your-own-adventure quoting style:

print(q{sed 's/ \.\.\.\.\.\.\.\./ /' file_a > file_b});

Or the here-doc style quotes:

print <<END;
sed 's/ \.\.\.\.\.\.\.\./ /' file_a > file_b
END


What's more, I think writing \.\.\.\.\.\.\.\. is not a good way.
There's perhaps a better and shorter format of this command.

As long as you are using sed to do the processing, then this between
you and sed. This is the wrong forum for that.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
.



Relevant Pages

  • Re: Need help with SQL injection proof recordset Update code
    ... attack is when you are dynamically building your one sql strings. ... quote with two single quotes by using the replace command. ...
    (microsoft.public.inetserver.asp.db)
  • Re: Need help with SQL injection proof recordset Update code
    ... attack is when you are dynamically building your one sql strings. ... quote with two single quotes by using the replace command. ... forget attempting to excape strings: ...
    (microsoft.public.inetserver.asp.db)
  • Re: How to deal with "{" in system("...command..."); ?
    ... I want to replace all strings of one blank followed by 8 dots ... one character. ... There's perhaps a better and shorter format of this command. ...
    (comp.lang.perl.modules)
  • Re: Backticks with single quote inside single quotes
    ... to use double instead of single quotes around the command argument. ... this doesn't work in my _real_ case because the actual command ... not split the entire script into a list of individual words, ... to an external program, avoid interpolating a shell. ...
    (comp.lang.perl.misc)
  • Re: Joining PDF Files with Ghostscript
    ... when I specify over 22 files it is not closing the output file. ... receiving error 25 closing the device ... That was what I was thinking of as the command limit, ... Single quotes are treated as part of the ...
    (comp.lang.postscript)