sar123 has asked for the wisdom of the Perl Monks concerning the following question:

I have the following input file:
xabcd a1 +b1 +b2 +b3 +b4 +b5 abcd xcdef c1 +d1 +d2 +d3 +d4 +cdef
I am trying to remove all the "+"signs and add the lines together to get output of the following type:
xabcd a1b1b2b3b4b5 abcd xcdef c1d1d2d3d4cdef
Here is my code for this:
#!/usr/bin/perl use warnings; use strict; use diagnostics; open my $fh, "<", "$ARGV[0]" or die "Could not open $!"; my @file = <$fh>; $/ = "\n+"; chomp (@file); print "@file\n";
But this gives the output same as the input file. What is wrong with code?

Replies are listed 'Best First'.
Re: Chomp in perl
by Athanasius (Archbishop) on Oct 05, 2014 at 06:12 UTC
      Thanks again...:)
Re: Chomp in perl
by rnaeye (Friar) on Oct 05, 2014 at 16:23 UTC
    The following also seems to work on my computer:
    #!/usr/bin/perl use warnings; use 5.16.2; $/ = "\n+"; while (<DATA>) { if ($_ =~ m/\+/) { s/\n\+//; } print; }

      Added  __DATA__

      #!/usr/bin/perl use warnings; use 5.16.2; $/ = "\n+"; while (<DATA>) { if ($_ =~ m/\+/) { s/\n\+//; } print; } say ''; __DATA__ xabcd a1 +b1 +b2 +b3 +b4 +b5 abcd xcdef c1 +d1 +d2 +d3 +d4 +cdef