> Is there a way to determine the number of lines
> in a file without actually iterating through the
> file and incrementing a file?
No.
> I found the following on perlmonks.org, it works
> great but this is command line syntax
When you deparse that command (see below), you can see that all it does is
read each line of the file and set $_ to the line number (*.). After
reading in each line it then prints the result. So there is no silver
bullet.
$ perl -MO=Deparse -lpe '}{*_=*.}{' file
LINE: while (defined($_ = <ARGV>)) {
chomp $_;
}
{
*_ = *.;
}
{
();
}
continue {
die "-p destination: $!\n" unless print $_;
}
-----Original Message-----
From: Jason Normandin [mailto:[EMAIL PROTECTED]
Sent: Wednesday, February 25, 2004 6:56 PM
To: Perl Beginners
Subject: Count the number of lines in a file without actually iterating
through the file
Hi List.
Is there a way to determine the number of lines in a file without actually
iterating through the file and incrementing a file?
I found the following on perlmonks.org, it works great but this is command
line syntax
:
perl -lpe '}{*_=*.}{' file
How could I integrate this into a script without invoking another instance
of Perl?
Thanks !
~Jason
------------------------------------
"If, after the first twenty minutes, you don't know who the sucker at the
table is, it's you."
------------------------------------
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>