[plug] Perl query: Counting letters in a string.

Anthony J. Breeds-Taurima tony at cantech.net.au
Thu Feb 20 16:58:27 WST 2003


On Thu, 20 Feb 2003, David Buddrige wrote:

> Hi all, 
> 
> I need to write a perl program that will identify any lines in a C++ source 
> file that are > 80 characters long, and chop them into 2 lines at an 
> appropriate point in the string.  However, in order to do this, I need to 
> determine how long the string is. 
> 
> The script consists of the following loop: 
> 
> while(<>)
> {
>  $line_of_code = $_;
>  # Now count the characters in $line_of_code and process if > 80.
> } 
> 
> Can someone let me know how to determine how many characters are in 
> $line_of_code? 

As Matt has already pointed out you can use the length function to do this.

Have you considered useing the "indent" (or even the BSD indent) GNU tool.
it does a great job and has waaay more options than you'll ever need.

Yours Tony.

/*
 * "The significant problems we face cannot be solved at the 
 * same level of thinking we were at when we created them."
 * --Albert Einstein
 */



More information about the plug mailing list