This is related to this question
Where combination of all lines that end with a backslash character is done. The following Perl command works in terminal but not in Perl script:
perl -i -p -e 's/\\\n//' input_file
In Perl script, I set it this way but it does not work:
`perl -i -p -e 's/\\\n//' $input_file_path_variable`;
**Updated the file content and code used
Input file content as follows:
foo bar \
bash \
baz
dude \
happy
Desired output content:
foo bar bash baz
dude happy
Current script:
#!/usr/bin/env perl
use Getopt::Long;
use FindBin;
use File::Path;
use File::Copy;
use DirHandle;
use FileHandle;
use File::Basename;
use Env;
use File::Slurp;
my $dummy_file = "/wdir/dummy.txt";
my $file_content = read_file($dummy_file);
print "$file_content\n";
print "==============================================\n"
my $ttest = $file_content =~ s/\\\n//;
print "$ttest\n";
Current Output
foo bar \
bash \
baz
dude \
happy
==============================================
1
\\becomes\in double-quoted string literals. /// Also, you have a code injection bug. That's not the proper way to create a shell command. See String::ShellQuote. /// Finally, why are you using backticks for a program that produces no output to STDOUT? You could avoid having to use String::ShellQuote by using the multi-argument form ofsystem.