Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Reading from a file

by LanceDeeply (Chaplain)
on May 23, 2006 at 11:10 UTC ( #551128=note: print w/replies, xml ) Need Help??


in reply to Reading from a file

are you running on linux?
my $first_line = qx/head -1 $filename/; print $first_line; my $last_line = qx/tail -1 $filename/; print $last_line; my $n = 100; my $nth_line = qx/tail +$n $filename | head -1/; print $nth_line;

-hth

Replies are listed 'Best First'.
Re^2: Reading from a file
by just dave (Acolyte) on May 23, 2006 at 12:11 UTC
    Hello and thank you all!
    A few answers:
    1. yes, I'm running on linux !!
    2. this is a reporter file, it gets appended all the time, every minute or so
    3. the last line is the most updated(since the report row /line is added every minute), that's why I'm interested in it, and I used to read the first line too since it holds the columns name(I get the data by the column name) BUT
    now I found a bug- if a change is made, and a column is added,then a new row is added (similar to the first row holding the names) but this row also holds the name of the new column, BUT it doesn't know about it since it reads the column name from the first row in the file
    So, I need to change this and search the file for this row and if it's not found-I'll end up with the first one

    It look something like this:
    #name: time input output users connected ... 12:23 23 34 780 560 12:24 21 40 780 570 ....
      ok-
      in keeping with the *nix commands theme how about:
      # # find last row that defines the columns ( i.e. starts with #name: ) # my $column_names = qx/grep ^\#name $filename | tail -1/; print $column_names;
      -hth

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2021-05-11 01:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (111 votes). Check out past polls.

    Notices?