in reply to Smart way to read a file vertically?

use warnings; use strict; my %data; while (<DATA>) { my @cols = split; push @{ $data{first} }, $cols[0]; push @{ $data{last } }, $cols[1]; push @{ $data{phone} }, $cols[2]; push @{ $data{email} }, $cols[3]; } for my $item (qw(first last phone email)) { print "$item\n"; print "$_\n" for @{ $data{$item} }; print "\n"; } __DATA__ John Smith 1234 lala@lala.com Peter Jones 6789 ttt@yahoo.com George Lukas 9086 lll@hotmail.com

prints out:

first John Peter George last Smith Jones Lukas phone 1234 6789 9086 email lala@lala.com ttt@yahoo.com lll@hotmail.com

Replies are listed 'Best First'.
Re^2: Smart way to read a file vertically?
by Not_a_Number (Prior) on Jun 06, 2012 at 22:06 UTC

    This fails for 'Mary Lou Retton' and 'Ludwig van Beethoven'.