in reply to getting line count in cmd.exe

perl -pe'}{$\=$.' filename

Replies are listed 'Best First'.
Re^2: getting line count in cmd.exe
by ww (Archbishop) on Sep 15, 2008 at 02:02 UTC
    Just FTR, appears (testing with 5.8 and w2k against .pl and (ASCII text) .txt files as the targets) that this produces an accurate count on the .pl files, but not so with those named *.txt.

    First suspicion was that some doubled \n instances might be the problem, but further runs aginst .txt files without blank lines disabused me of that: perl -pe"}{$\=$." f:\_wo\(various).txt, consistently undercounted the lines.

    Is it just late on a hot, sticky and perhaps "stupidity-inducing" night, or do others see this too?

      There's no reason why that should be. Why would <> returns something different based on the input's extension.

      >perl -MO=Deparse -pe"}{$\=$." LINE: while (defined($_ = <ARGV>)) { (); } { $\ = $.; } continue { die "-p destination: $!\n" unless print $_; } -e syntax OK

      And I don't see it happening

      >perl -pe"}{$\=$." script.pl 56 >copy script.pl test.txt 1 file(s) copied. >perl -pe"}{$\=$." test.txt 56

      Provide a hexdump of your text file if you want to look into this further.

        My error was in failing to unwrap lines.

        Meh; duh!

        Thanks for putting me on the right track.