in reply to
Shortcut to identify column numbers in a data file based on header
Its not clear how you will receive the file or parse it but once you have managed that task you can use a hashref for look-up to retrieve values in a table. The only caveat being that the header lookup must be built individually for each file.
#! C:/Perl/bin/perl
use strict;
use warnings;
my $file_ref =[
[ 'Non-Syn', 'Splice', 'dbSNP', 'N (Var Depth)', 'N Total Depth',
+'N Freq', 'T (Var Depth)', ],
[ qw( 1 0 0 0 34 0 11 )],
[ qw( 1 0 0 0 54 0 14 )],
[ qw( 1 0 0 0 42 0 11 )],
];
my $header_hash_ref = _load_header( $file_ref->[0] );
my $line = 3;
my $header = 'N Total Depth';
print "Line -$line- '$header' value is:" .
$file_ref->[$line]->[$header_hash_ref->{$header}] .
"\n";
sub _load_header{
my ( $header_ref ) = @_;
my ( $return, $x ) = ( {}, 0 );
for my $header ( @$header_ref ){
$return->{$header} = $x++;
}
return $return;
}
Provides the output
Line -3- 'N Total Depth' value is:42