Is your data in fixed-width columns? It looks like it might be, and unpack is the function of choice for that.

If it is tab delimited, instead, @split_array = split /\t/; will do the job.

If your data file is so messy that neither is true and you have only approximate gobs of whitespace, you can try to limit the amount of whitespace you split on with something like split /\s{1,8}/; (adjusted to fit).

Instead of slurping, why not do this line-by-line as you read the file?

my ($testnumber, $llimit, $value, $ulimit, $unit, $name) = 0..5; while (<INFILE>) { my @split_array = split /\t/; # or whatever printf 'TestNum = %s Value = %s Name = %s Ulimit = %s Llimit = %s.', @split_array[$testnumber, $value, $name, $ulimit, $llimit]; }
I changed the variables to hold their index in the record so they don't have to be reallocated all the time. The array slice uses those indexes to pick out the values for printf. If the numeric data gets used numerically before printing, you may want a fancier format string in printf.

Update: ++blokhead spotted a thinko, repaired.

After Compline,
Zaxo


In reply to Re: Beginner Question on splitting. by Zaxo
in thread Beginner Question on splitting. by BigSmith

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.