Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jonasbn (1153)

  reversethis-{gro.napc} {ta} {nbsanoj}
AOL IM: BJonasN (Add Buddy, Send Message)

Perl Programmer located in Copenhagen, Denmark. Active member of Copenhagen Perl Mongers.

Author of:

  • Business::DK::CPR
  • Business::DK::CVR
  • Business::DK::PO
  • Business::OnlinePayment::CashCow
  • Date::Holidays
  • Date::Holidays::Abstract
  • Date::Holidays::Super
  • Date::Pregnancy
  • Games::Bingo
  • Games::Bingo::Bot
  • Games::Bingo::Print
  • Module::Info::File
  • Module::Template::Setup
  • Test::Timer

and maintainer of:

  • Tie::Tools
  • XML::Conf
  • Workflow

Journal of jonasbn (1153)

Saturday June 28, 2003
07:11 AM

wc command on OS X acting weird?

[ #13115 ]

I am revisiting an old project where I want to make some statistics on lines of code.

In order to check whether was I was doing was completely crazy I checked the file in question with the wc command.

hyperstation ~/Develop/Copenhagen/modules/Metrics/LOC % wc t/LOC.t
            41 122 956 t/LOC.t

This differs a bit from my Perl code, which says it contains 42 lines... so I tried grep.

hyperstation ~/Develop/Copenhagen/modules/Metrics/LOC % grep -c "" t/LOC.t

The man page for wc states

A line is defined as a string of characters delimited by a character

So that is probably the reason, but it still annoys me, heh maybe I should entitle this entry, 'Using wc considered harmful', or maybe I just had too much coffee...

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • wc's linecount simply counts newlines. By definition, Unix text files should have a newline at the end of the last character. If it doesn't, the last line is "incomplete", and the linecount will be off by one.

    At worst, wc will be one line off because the trailing newline is missing. (vi/vim can show a warning about this as well.)