[plug] Perl query: Counting letters in a string.
Bret Busby
bret at busby.net
Thu Feb 20 17:02:16 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?
>
> thanks heaps
>
> David.
>
>
>
My knowledge of Perl is not great, but, wouldn't you do it by counting
characters in the string, until an end of line character is encountered?
Also, depending on your reason for splitting the lines, wouldn't you
need to insert a continuation character in a split line of code?
--
Bret Busby
Armadale
West Australia
..............
"So once you do know what the question actually is,
you'll know what the answer means."
- Deep Thought,
Chapter 28 of
"The Hitchhiker's Guide to the Galaxy:
A Trilogy In Four Parts",
written by Douglas Adams,
published by Pan Books, 1992
....................................................
More information about the plug
mailing list