I
io
Kind folks of Perlidom-
My intent is to slurp a big text file (say, a chapter from the
English literature). I then want to trim all the white space and
newlines, so I get an array of compact text. I've looked into the
Perl Cookbook, and came up with this.
However, it doesn't work. The array slurped up has as many spaces as
the original. In fact, it looks the same.
####################################
#!/usr/bin/perl
use warnings;
open INPUT, "textfile" or die $1;
my @data;
while(<INPUT>) {
my $fh = <INPUT>;
chomp $fh;
$fh =~ s/^\s+//;
$fh =~ s/\+$//;
push @data, $fh;
}
print @data, "\n";
###################################
Is the issue the print statement? Is it the stream? Is it a scope
issue with push @data?
I don't get it! Please help...
TIA.
My intent is to slurp a big text file (say, a chapter from the
English literature). I then want to trim all the white space and
newlines, so I get an array of compact text. I've looked into the
Perl Cookbook, and came up with this.
However, it doesn't work. The array slurped up has as many spaces as
the original. In fact, it looks the same.
####################################
#!/usr/bin/perl
use warnings;
open INPUT, "textfile" or die $1;
my @data;
while(<INPUT>) {
my $fh = <INPUT>;
chomp $fh;
$fh =~ s/^\s+//;
$fh =~ s/\+$//;
push @data, $fh;
}
print @data, "\n";
###################################
Is the issue the print statement? Is it the stream? Is it a scope
issue with push @data?
I don't get it! Please help...
TIA.