Hello esteemed Monks of perl
I am being stumped on why my data is being slurped in all at once instead of line by line. I am trying to pull out only the name and id number, but my array is being loaded with the entire file. Also do I need to clear the array after each record read. I know it must be something simple because I've been staring at it for an hour.
Thanks, for your wisdom
#!/prod/bin/perl use strict; use warnings; use Data::Dumper; undef $/; my @data; my $counter = 0; while (my $line = <DATA>) { @data = split (/\t/, $line); print Dumper \@data; $counter = $counter+1; print "$counter, $data[11], $data[12]\n"; } __DATA__ LIMITS LIMITS1 LIMITS2 LIMITS3 LIMITS4 LIMITS5 LIMIT +S6 LIMITS7 UPDATEDATE STEP2 DESC2 APPR2 APPRID2 +OWNR2 OWNRID2 Limits less than $1K $1K-50K $50k-$250K more than $250K + $250K-$1M $1M-$5M more than $5M 8/16/2006 2:14:00.000 PM + 111111 Cost Center 1 Stien, Franklin N 000204 Stien, Fra +nklin N 000204 Limits less than $1K $1K-50K $50k-$250K more than $250K + $250K-$1M $1M-$5M more than $5M 8/16/2006 2:14:00.000 PM + 222222 Cost Center 2 Bear, Izzy 000598 Bear, Izzy 000 +598 Limits less than $1K $1K-50K $50k-$250K more than $250K + $250K-$1M $1M-$5M more than $5M 8/16/2006 2:14:00.000 PM + 333333 Cost Center 3 Bear, Fozzy 000485 Davis, Sammy +000404 Limits less than $1K $1K-50K $50k-$250K more than $250K + $250K-$1M $1M-$5M more than $5M 8/16/2006 2:14:00.000 PM + 444444 Cost Center 4 Frog, Kermit T 000990 Frog, Kermit +T 000990 Limits less than $1K $1K-50K $50k-$250K more than $250K + $250K-$1M $1M-$5M more than $5M 8/16/2006 2:14:00.000 PM + 555555 Cost Center 5 Cleavland, Grover 000563 Cleavland, + Grover 000563

-- Grey Fox
Perl - Hours to learn lifetime to master.

In reply to Why is file being slurped in instead of line by line? by Grey Fox

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.