Edward WIJAYA wrote:
Hi John,

Hello,

I tried your code.
But I still cannot remove the whitespace from each line.

Suppose I have two files.

fileA.txt:    fileB.txt:
A             B
A             B

What I get is:
A B
A B

instead of
AB
AB

I tried to play around with this
section of your code but of no avail.

# clean up whitespace
for ( @data ) {
     s/^\s+//;
     s/\s+/ /g;
     s/ $/\n/;
     }

This should do what you want:

#!/usr/bin/perl
use warnings;
use strict;

my ( $line, @data );
while ( <> ) {
    s/^\s+//;
    s/\s+$//;
    s/\s+/ /g;
    $data[ $line++ ] .= $_ if /\S/;
    $line = 0 if eof;
    }

print map "$_\n", @data;

__END__



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to