grep all records in a file and get a word count -perl

Hi,

I have a file .. file.txt .. i need to get a total record count in the files into a $variable.. im using perl script

thanks

wc -l filename gives a record count for a file
in perl

$variable = `wc -l filename`

wc -c counts the words in a file. It is hard to see which one you want.

Hey thanks for the reply.. but
wc -l filename ... gives (say count is 200)

output:
200 filename

-- the count includes filename too.. and i want to avoid it..

Thanks

Not sure how efficient this is

open (FH, 'filename');
(1) while (<FH>);
my $wc = $. || 0;
print $wc;

$. is the input file line/record number. The way I used it it will give the last record number of the last file opened, if you need the record number for multiple files push $. into an array instead of assigning to a scalar.

a simple split on the variable and getting the first element will do it. look up
perldoc -f split..
please read through the Perl docs