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