Reputation: 534
I'm trying to remove the string @my.mail.com from the file - list.txt, using the one liner from my perl script. (Perl script is kicked off from windows server)
r12355 [email protected]
r29555 [email protected]
r29555 [email protected]
@my.mail.com
r295721 [email protected]
r295722 [email protected]
@my.mail.com
r295140 [email protected]
r295145 [email protected]
@my.mail.com
Below are the options I have tried while calling inside the perl script:
`perl -pi.bak -e 's/\s+\@my\.mail\.com\s+//g;' D:\\myfolder\\list.txt`;
system("perl -pi.bak -e 's/\s+\@my\.mail\.com\s+//g;' D:\\myfolder\\list.txt");
system( q( perl -l -pi.bak -e 's/\s+\@my\.mail\.com\s+//g;' D:\\myfolder\\list.txt ) );
I'm expecting result like
r12355 [email protected]
r29555 [email protected]
r29555 [email protected]
r295721 [email protected]
r295722 [email protected]
r295140 [email protected]
r295145 [email protected]
Not sure If I'm missing something silly , any inputs are really appreciated. Thanks in advance!
Upvotes: 0
Views: 166
Reputation: 126722
There are two problems here. Firstly you have escaped the backslashes in the file path but not in the regex pattern, and secondly you have used single quotes around the parameter to the -e
option, which Windows doesn't recognise as delimiters
This variation should work for you. It uses single quotes (actually q{...}
) to protect the backslashes so that nothing needs to be escaped
system q{perl -pi.bak -e "s/\s+\@my\.mail\.com\s+//g" D:\myfolder\list.txt};
However it is poor practice to shell out to another perl process from within your Perl program. It can be done directly in your main code by adding this, which is much more readable and less easy to get wrong
{
local @ARGV = 'D:\myfolder\list.txt';
local $^I = '.bak';
while ( <> ) {
s/\s+\@my\.mail\.com\s+//g;
print;
}
}
Upvotes: 3