Perl System Error – Troubleshooting System() Function

linuxperlscriptingsedshell

'

Number found where operator expected at ./scripttemp.perl line 5, near
""sed -i -r "4" (Missing operator before 4?) String found where
operator expected at ./scripttemp.perl line 5, near "}" error.txt""
(Missing operator before " error.txt"?) syntax error at
./scripttemp.perl line 5, near ""sed -i -r "4" syntax error at
./scripttemp.perl line 5, near "s/[-.*-]//g}" Execution of
./scripttemp.perl aborted due to compilation errors. '

I am getting this error running my script :

**#!/usr/bin/perl
use warnings;
use strict;
exec("sed -i -r "4{s/\{\+//; s/\+}//; s/\[-.*-]//g}" error.txt");**

Please tell me what is wrong?

Best Answer

It's your use of double quotes. You cannot use double quotes "inside" double quotes unless they are escaped. Instead you could either escape your double quotes or more preferrably alternate quotes by using single quotes instead:

#!/usr/bin/perl
use warnings;
use strict;
exec("sed -i -r '4{s/\{\+//; s/\+}//; s/\[-.*-]//g}' error.txt");
Related Question