Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Handing files in CGI/Perl

InFeStEdInFeStEd Member Posts: 32
[b]Situation[/b]:
I had programmed something to read a file, but first it needs to know how many lines are in the file total. To get the amount of lines in the file I used this code:

[italic]open(READFILE, $file_path);

while ($line = )
{
++$line_count;
}

close(READFILE);[/italic]

[b]Problem[/b]:
That code is so big and it must take up much processing.

Can anybody provide me with a function that will get the amount of lines in a file?

And can somebody also provide me with a function that will set the file pointer to skip lines and read at a specified point?

Thank you


Comments

  • hhcohhco Member Posts: 7
    : [b]Situation[/b]:
    : I had programmed something to read a file, but first it needs to know how many lines are in the file total. To get the amount of lines in the file I used this code:
    :
    : [italic]open(READFILE, $file_path);
    :
    : while ($line = )
    : {
    : ++$line_count;
    : }
    :
    : close(READFILE);[/italic]
    :
    : [b]Problem[/b]:
    : That code is so big and it must take up much processing.
    :
    : Can anybody provide me with a function that will get the amount of lines in a file?
    :
    : And can somebody also provide me with a function that will set the file pointer to skip lines and read at a specified point?
    :
    : Thank you
    :

    Here is an easy way of finding how many lines exist in the file

    open (INF, "m.dat") or dienice("Can't open file");
    @ary = ;
    close(INF);

    $length = @ary; # you can also use $#ary which will return the
    # index value of the last line

    print "$length";

    I hope that helps...





Sign In or Register to comment.