Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Reading from a file

by TedPride (Priest)
on May 23, 2006 at 21:39 UTC ( [id://551241]=note: print w/replies, xml ) Need Help??


in reply to Reading from a file

You can read the first line using the regular method - open, read to first record delimiter. Then just split to get your field names, and convert them to a hash so you can find the proper field in later records. That's no problem, even if fields are added or removed.
chomp($record = <DATA>); $keys{$_} = $c++ for split / /, $record; ## Get last record and put it in $record @record = split / /, $record; print $record[$keys{'timestamp'}];
The harder part is getting at the last record. For this, jump to the end of the file minus whatever the maximum possible record size could be (+ record delimiter), then read everything from there to the end and retrieve the last record. Again, not that difficult.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-19 17:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found