perl -ne '$c += tr/A/A/; print $c if eof;' file
Doesn't this fail if the file is empty?
Dale Worley Compass, Inc. wor...@compass.com
--
Using MS-DOS on a '386 is like using a Formula 1 race car to do your
grocery shopping.
Ooops. I'll be out painting fence-posts for a while, sorry. :-)
--
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III |
| mer...@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/
| 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
Dale Worley Compass, Inc. wor...@compass.com
--
Give yourself over to absolute pleasure
Swim the warm waters of sins of the flesh
Erotic madness beyond any measure
And sensual daydreams to treasure... forever.
-- Rocky Horror Picture Show
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