in reply to Re: How To Count Lines In File?
in thread How To Count Lines In File?

Is there any gain in using globs over the variables themselves, such as:
perl -lpe '}{$_=$.' file
?

On another similar note, last semester my C++ students had to write a small C++ program that averages numbers from a flatfile (one per line). I wowed them with this little doosie:

perl -lpe '$s+=$_}{$_=$s/$.' file
UPDATE
That's a fair cop! :)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: How To Count Lines In File?
by Abigail-II (Bishop) on Jan 27, 2003 at 21:46 UTC
    Is there any gain in using globs over the variables themselves

    If you can answer the question "is there any gain in using perl -ple '}{*_=*.}{' file over wc -l file", you can figure out the other question yourself.

    Abigail

      not all systems have wc - now what about the globs?

        Not all systems have perl either - now about those globs: no gain.

        -sauoq
        "My two cents aren't worth a dime.";