Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2022-12-03 19:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?