Anirban Adhikary wrote:
Dear List
Hello,
I have a source file as follows
hello how are you?
hello how are you?
What language did you want to use?
What language did you want to use?
I am here
You are there
this is my first perl script
What language did you want to use?
####################################################
I want to write a script which will take a single line from the filehandel
and print the line without any space between words of that line
Just "space"? Does that also include TAB characters and other whitespace?
I have written a code as follows( I can achieve this by using an array but I
don't want to use an array)
use strict;
use warnings;
my $fname="/home/anadhikary/perl/file1.txt";
open my $FH,'<',$fname;
You should always verify that the file opened correctly:
open my $FH, '<', $fname or die "Cannot open '$fname' $!";
while(<$FH>)
{
my ($line)=split(/\s+/,$_);
print $line."\n";
s/\s+//g;
print "$_\n";
}
close($FH);
But this code prints only the first words of every line....
Where I am making the mistake???
split() returns the list of non-whitespace character strings but you are
only assigning from the first element of that list. Your code should
have been something more like:
my $line = join '', split;
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/