Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Count number of lines?

by CheeseLord (Deacon)
on Jun 20, 2001 at 06:44 UTC ( [id://89898]=note: print w/replies, xml ) Need Help??


in reply to Count number of lines?

Well, I'm not exactly one to ask about Perl and CGI (as I haven't done very much of it), but if you've got Perl down reasonably well, I'd suggest looking at "CGI Programming with Perl" from O'Reilly. It helped me out a good deal with the little I've done. If you're still working with Perl, I'd recommend getting that down first -- in which case, there's always the Camel (and/or Llama) book.

And about your number of lines question:

sub numlines { my $file = shift @_; unless (open FILE, "$file") { warn "Could not open $file: $!\n"; return -1; # Only a recommendation } my @lines = <FILE>; close FILE; return scalar @lines; }

I don't know if there's a way to determine the number of lines in a file without reading the entire thing... you might also want to look up perlvar and check out $., as that likely has the "cooler" way to accomplish that task. Hope that helps!

His Royal Cheeziness

Log In?
Username:
Password:

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

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

    No recent polls found