I have written a script that saves the output in a Perl script, but for some reason it is leaving the space at the end of each line. I tried using Perl regex but it does not work. Can someone please look at my code and let me know what I am doing wrong?
MY CODE
open FILE, ">", "finaloutput.txt" || die "cannot create";
my @output = ``; # (here i am using back ticks to run third party command)
foreach my $output (@output) {
chomp $output;
my $remove_whitespace = $output;
$remove_whitespace =~ s/^\s+|\s+$//g;
print FILE "$remove_whitespace \n";
}
close FILE;
Even after doing this it is leaving a white space at the end of each line in output. Please guide me.
Thanks.
You’re putting two spaces at the end of every line:
Get rid of those! Solutions: