Click here to get back home

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

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
How to deal with "{" in system("...command..."); ? Kuhl 08-13-2008
Get Chitika Premium
Posted by Kuhl on August 13, 2008, 8:42 am
Please log in for more thread options


Hi, all:

In order to replace }PERM= into PERM= in a file, I ran a command:
sed "s/}PERM=/PERM=/" record_with_comment_tmp > record_with_comment

It works.

I need to run it in a Perl script. So I wrote the following command in
the Perl script:
system ("sed "s/}PERM=/PERM=/" record_with_comment_tmp >
record_with_comment");

But the script cannot run. When I tried to run it, it gives following
error message:
String found where operator expected at drccomp_Her_debug.pl line 41,
near "/PERM=/" record_with_comment_tmp > record_with_comment""
(Missing operator before " record_with_comment_tmp >
record_with_comment"?)

I changed the double quotation mark around s/}PERM=/PERM=/ into single
quotation mark like:
system ("sed 's/}PERM=/PERM=/' record_with_comment_tmp >
record_with_comment");

The system still shows error message like:
String found where operator expected at drccomp_Her_debug.pl line 41,
at end of line
(Missing semicolon on previous line?)

But in fact, I am not missing semicolon on previous line.

I also tried several ways using \ or using ` `, but still failed.
What's wrong with this command? What's the correct way to do it?

Thanks.

Posted by John W. Krahn on August 13, 2008, 9:28 am
Please log in for more thread options


Kuhl wrote:
> Hi, all:
>
> In order to replace }PERM= into PERM= in a file, I ran a command:
> sed "s/}PERM=/PERM=/" record_with_comment_tmp > record_with_comment
>
> It works.
>
> I need to run it in a Perl script. So I wrote the following command in
> the Perl script:
> system ("sed "s/}PERM=/PERM=/" record_with_comment_tmp >
> record_with_comment");
>
> But the script cannot run. When I tried to run it, it gives following
> error message:
> String found where operator expected at drccomp_Her_debug.pl line 41,
> near "/PERM=/" record_with_comment_tmp > record_with_comment""
> (Missing operator before " record_with_comment_tmp >
> record_with_comment"?)
>
> I changed the double quotation mark around s/}PERM=/PERM=/ into single
> quotation mark like:
> system ("sed 's/}PERM=/PERM=/' record_with_comment_tmp >
> record_with_comment");
>
> The system still shows error message like:
> String found where operator expected at drccomp_Her_debug.pl line 41,
> at end of line
> (Missing semicolon on previous line?)
>
> But in fact, I am not missing semicolon on previous line.
>
> I also tried several ways using \ or using ` `, but still failed.
> What's wrong with this command? What's the correct way to do it?

open my $IN, '<', 'record_with_comment_tmp' or die "Cannot open
'record_with_comment_tmp' $!";
open my $OUT, '>', 'record_with_comment' or die "Cannot open
'record_with_comment' $!";
while ( <$IN> ) {
s/}PERM=/PERM=/;
print $OUT $_;
}
close $OUT;
close $IN;




John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

Posted by xhoster on August 13, 2008, 11:55 am
Please log in for more thread options


> Hi, all:
>
> In order to replace }PERM= into PERM= in a file, I ran a command:
> sed "s/}PERM=/PERM=/" record_with_comment_tmp > record_with_comment
>
> It works.

Since you are already using Perl, it probably makes sense to use it for
this too, rather than using sed.

...
> I changed the double quotation mark around s/}PERM=/PERM=/ into single
> quotation mark like:
> system ("sed 's/}PERM=/PERM=/' record_with_comment_tmp >
> record_with_comment");

This code works for me, assuming it is all on one line.

>
> The system still shows error message like:
> String found where operator expected at drccomp_Her_debug.pl line 41,
> at end of line
> (Missing semicolon on previous line?)
>
> But in fact, I am not missing semicolon on previous line.

Then you are probably doing something else wrong on some previous line.
We can't know what we can't see.

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.

Posted by Kuhl on August 13, 2008, 3:59 pm
Please log in for more thread options


OK, I will try using while ( <$IN> ) { ... } also.

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.

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

What's the correct way to achieve my purpose?

Thanks.

Posted by Jim Gibson on August 13, 2008, 7:24 pm
Please log in for more thread options


In article

> OK, I will try using while ( <$IN> ) { ... } also.

Please include a little context in your posts. We are not all using
Google Groups.

>
> 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.

In double-quote context as above, Perl will interpret "\." as a dot
character, and sed will receive s/ ......../ /. You can double up on
the backslashes if you want sed to get s/ \.\.\.\.\.\.\.\./ /:

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

> What's more, I think writing \.\.\.\.\.\.\.\. is not a good way.
> There's perhaps a better and shorter format of this command.
>
> What's the correct way to achieve my purpose?

s/ \./ /g;

or

s/ [.]/ /g;

--
Jim Gibson

Similar ThreadsPosted
How Do You Get LWP To Deal With Javascript "Pop-Ups" October 20, 2005, 3:02 pm
DFA::Command V 1.98 July 29, 2004, 7:18 am
system return value? January 26, 2007, 5:52 pm
Help: "find command in windows" July 23, 2005, 1:25 pm
how to execute command on remote machine September 21, 2005, 12:40 am
IO::Pty - reads/writes fail *only* with system() January 10, 2006, 1:59 pm
System call fails in webserver February 11, 2006, 11:04 am
Search for a job online from command line May 31, 2007, 5:44 am
Search eBay from command line May 31, 2007, 11:33 am
List of all modules installed on a system August 8, 2007, 1:41 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap