Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Re: path is broken

by gaspodethewonderdog (Monk)
on Dec 07, 2000 at 00:03 UTC ( [id://45300]=note: print w/replies, xml ) Need Help??


in reply to Re: path is broken
in thread path is broken

that's well and good... but what if the file is large? why not do basically the same thing except...
use strict; my $filename = "foo.txt"; my $count; open FILE, $filename or die "could not open $filename"; while(<FILE>) { $count++; } # while close FILE; print $count;
I imagine it should run about the same speed wise, but shouldn't require quite so much memory...

Replies are listed 'Best First'.
(Ovid) Re(3): path is broken
by Ovid (Cardinal) on Dec 07, 2000 at 00:15 UTC
    Perl keeps track of the line number of the file you are in so you don't have to:
    perl -e "while(<>){};print $." somefile.txt
    Gotta love that $. variable :)

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

      I particularly like this code, posted by Abigail on (I believe) comp.lang.perl.misc:
      perl -wlpe '}{*_=*.}{' <file>
      There's a lot of $. (<-- that dot is a regex =]) variables to love, yet I've only stumbled across a few of them, and even less explanations of what those variables do. Anyone know of a comprehensive listing of what variables are available to us in the $/./ (<-- that is a correct regex!) format and what they all do? I haven't noticed it in any of my books (I haven't read all of every book yet, so standard disclaimer of "i may be a fool" applies here).

      -marius

        As merlyn is not around I will have to sub and give you the ob. reference:

        perldoc perlvar

        will give you the entire list.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-23 21:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found