Torqued wrote:
I have a code which goes like this
#!/usr/bin/perl -w
use strict;
my @column;
while (<DATA>) {
push @column, (split)[0];
print join (' ', @column);
}
__DATA__
1 a b c
2 d e f
3 g h i
But when running this i get the output as : 11 21 2 3
Whereas i am trying to get the output as : 1 2 3
could you please suggest what i am doing wrong here?
You are printing the contents of @column while inside the loop. You
need to print after the loop has ended:
my @column;
while (<DATA>) {
push @column, (split)[0];
}
print join (' ', @column);
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/