Extracting Whitespaces HTML/CGI (really easy)

(this is more of an html/cgi problem i guess)

How do i extract whitespaces from a TEXTAREA and count how many characters there are?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Please explain some more about what you are asking.

When your CGI script receives the request from the user's browser, the form variables, including the TEXTAREA will be accessible (if you are using the CGI module, as you probably should) as

$txt = param('name_of_text_area');

The character count you are after may be as simple as "length($txt)". As for extracting whitespaces, you need to explain: are you asking how to remove _extra_ whitespace from the TEXTAREA, such as trimming extra spaces from the front and end? Or double spaces between words? Or what?
use CGI;
my $q = new CGI;
print scalar @n;

Okay, that's an interpretation: how many non-whitespace characters are there in the TEXTAREA? But why go through all those gyrations to get something that's equivalent to

print length($txt);

(I wonder if that needs a \n on the end?).
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

hmm, probably folloing what is asked for:

depending on interpretation of "extract whitespaces" ;-)
NeoHackerAuthor Commented:
sorry, i didnt mean EXTRACT them, i meant keep the whitespaces but COUNT the characters WITHOUT INCLUDING the whitespaces.
- i hope that clears thing up
Okay, Ahoffman had it right.

One recommended way to count characters is to use the 'tr' operator.

$count = $string =~ tr/ \t\r\n//c;

This does not actually change $string, but it counts all characters in the complement of the set specified as space, tab, carriage return, and line feed.
print scalar split(//,$x);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ahoffman, I don't want to criticize, but why do you take the extra (and expensive) step of splitting a string into an array of single characters just to count them? The number of characters in the string will always be more cheaply obtained using 'length'. Am I missing something?
> .. don't want to criticize
don't worry, I'm learning too, sometimes, somehow ;-)
The extra step? you mean split? then you're correct.
But how about more perlish:
  $_=$txt; print tr/ \t\r\n//c;
Ot if you don't want $_ to trash $_
  print tr/ \t\r\n//c for $txt;

Hasn't your question been answered? I recommend that you accept one of Ahoffman's responses and close this question. Otherwise, if there's still something we can do for you, please ask.
BTW, when using split() in a scalar context, it does not generate an array
NeoHackerAuthor Commented:
Ok, thanks ahoffman. Since you've helped me a lot on my questions, shouldn't i raise 20 points?

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.