Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Counting characters with unix utilities
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Larry Wall  
View profile  
 More options Sep 26 1990, 7:13 pm
Newsgroups: comp.lang.perl
From: lw...@jpl-devvax.JPL.NASA.GOV (Larry Wall)
Date: 26 Sep 90 18:21:45 GMT
Local: Wed, Sep 26 1990 2:21 pm
Subject: Re: Counting characters with unix utilities
In article <1990Sep26.125033.19...@uvaarpa.Virginia.EDU> wor...@compass.com writes:

:
:    From: mer...@iwarp.intel.com (Randal Schwartz)
:
:    |    perl -ne '$c += tr/A/A/; print $c if eof;' file
:    |
:    | Doesn't this fail if the file is empty?
:
:    Ooops.  I'll be out painting fence-posts for a while, sorry. :-)
:
: It seems like it would be useful to be able to prescribe prolog and
: epilog code for -n (and -p) loops.  AWK does this with BEGIN and END.
: Then it would be simple:
:
:       perl -ne '$c += tr/A/A/' -xxx 'print $c' file

It hardly seems worth it to add a new switch when you can say

        perl -e 'while(<>){$c += tr/A/A/;}print $c' file

or

        perl -ne '$c += tr/A/A/; print $c if eof()' file

or

        perl -e 'undef $/; $_ = <>; print tr/A/A/' file

or even

        perl -e '$c += tr/A/A/ while <>; print $c' file

Although the Perl Slogan is There's More Than One Way to Do It, I hesitate
to make 10 ways to do something.  :-)

Larry


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.