in reply to Extracting selected column names and values from tab delimited text file

Here's a working Perl solution:
use v6; my $data = q[colname1 colname2 colname3 val1 val2 val3 val11 val21 val31 val12 val22 val32]; my @lines = $data.split: "\n"; my @rows; my @header = @lines.shift.words; for @lines -> $l { my %h = @header Z $l.words; @rows.push: {%h}; } say @rows.perl; my @colname = <colname1 colname3>; say @colname.join("\t"); say $_{@colname}.join("\t") for @rows;

Though I admit that the output could be formatted a bit prettier, and some parts of the code are ugly hacks.

Perl 6 - links to (nearly) everything that is Perl 6.
  • Comment on Re: Extracting selected column names and values from tab delimited text file
  • Download Code