Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Shortcut to identify column numbers in a data file based on header

by jandrew (Hermit)
on Mar 27, 2012 at 18:25 UTC ( #961992=note: print w/ replies, xml ) Need Help??


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


Comment on Re: Shortcut to identify column numbers in a data file based on header
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://961992]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2014-12-19 15:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (84 votes), past polls