RE: Count the number of lines in a file without actually iteratin g through the file
From: Rob Hanson (rhanson_at_aptegrity.com)
Date: 02/26/04
- Next message: David Le Blanc: "RE: Perl Newbie"
- Previous message: David Le Blanc: "RE: get external process's output *and* return value"
- Next in thread: Wc -Sx- Jones: "Re: Count the number of lines in a file without actually iteratin g through the file"
- Reply: Wc -Sx- Jones: "Re: Count the number of lines in a file without actually iteratin g through the file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: 'Jason Normandin' <jason_normandin@charter.net>, Perl Beginners <beginners@perl.org> Date: Wed, 25 Feb 2004 19:25:53 -0500
> 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:jason_normandin@charter.net]
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."
------------------------------------
- Next message: David Le Blanc: "RE: Perl Newbie"
- Previous message: David Le Blanc: "RE: get external process's output *and* return value"
- Next in thread: Wc -Sx- Jones: "Re: Count the number of lines in a file without actually iteratin g through the file"
- Reply: Wc -Sx- Jones: "Re: Count the number of lines in a file without actually iteratin g through the file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|