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
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
:
: 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 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.
| ||||||||||||||