in reply to Smart way to read a file vertically?
Here's a generic technique to achieve what you want based on your supplied data.
#!/usr/bin/env perl use strict; use warnings; my @labels; my %col_data; while (<DATA>) { chomp; my @cells = split /\t/; if ($. == 1) { @labels = @cells; } else { push @{$col_data{$labels[$_]}} => $cells[$_] for (0 .. $#label +s); } } print join(qq{\n} => $_, @{$col_data{$_}}), qq{\n\n} for @labels; __DATA__ NAME LAST_NAME PHONE EMAIL John Smith 1234 lala@lala.com Peter Jones 6789 ttt@yahoo.com George Lukas 9086 lll@hotmail.com
Here's the output:
$ pm_read_vert.pl NAME John Peter George LAST_NAME Smith Jones Lukas PHONE 1234 6789 9086 EMAIL lala@lala.com ttt@yahoo.com lll@hotmail.com
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Smart way to read a file vertically?
by Anonymous Monk on Jun 06, 2012 at 09:07 UTC |