Similar to other solutions but using push with a ternary and maps.
use strict; use warnings; use 5.010; open my $inFH, q{<}, \ <<'EOD' or die qq{open: < HEREDOC: $!\n}; NAME LAST_NAME PHONE EMAIL John Smith 1234 lala@lala.com Peter Jones 6789 ttt@yahoo.com George Lukas 9086 lll@hotmail.com EOD my( @N, @LN, @P, @E ); push @{ $_->[ 0 ] == 1 ? \ @N : $_->[ 0 ] == 2 ? \ @LN : $_->[ 0 ] == 3 ? \ @P : \ @E }, $_->[ 1 ] for map { chomp; my $col = 0; map { [ ++ $col, $_ ] } split m{\t}; } <$inFH>; close $inFH or die qq{close: < HEREDOC: $!\n}; say for @N, q{}, @LN, q{}, @P, q{}, @E;
The output.
NAME John Peter George LAST_NAME Smith Jones Lukas PHONE 1234 6789 9086 EMAIL lala@lala.com ttt@yahoo.com lll@hotmail.com
I hope this is of interest.
Update: As pointed out by Not_a_Number, the code would have failed for some names. I had forgotten to put tabs back into the data after the copy'n'paste put in the displayed spaces :-(
Code now corrected.
Cheers,
JohnGG
In reply to Re: Smart way to read a file vertically?
by johngg
in thread Smart way to read a file vertically?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |