Say I have a file with a header, and I want to read this file into a perl script and figure out which columns are which automatically based on pattern matching. Is there a trick in perl to have it return the column number without reading the header in as an array, split by field, and then for looping through the array?

Heres an example data input at the bottom, but the columns are always going to be in different order so I want a script to match the column header and then return the column number that that column header matched so I can set it equal to a variable and use it like this later print if $array[$variable] >15 (just and example)

Does anyone know the most efficient quick way to do something like this or is the only way to split the header into an array and looping through it for each variable you want to match and give a value? Thank you for your time!

Non-Syn Splice dbSNP N (Var Depth) N Total Depth N Freq + T (Var Depth) 1 0 0 0 34 0 11 1 0 0 0 54 0 14 1 0 0 0 42 0 11

In reply to Shortcut to identify column numbers in a data file based on header by ZWcarp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.