CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
word count



Nov 6, 2000, 11:42 PM

Post #1 of 5 (1107 views)
word count Can't Post

I have a for loop in this loop I am passing names of diferent lengths, how can I get only the words with 4 letters or less to be proccessed by the if statement. I have tried statements similar to this can not get it to work
if echo $var1 | wc -c -le "4"

Thanx Raven


Nov 6, 2000, 10:57 PM

Post #2 of 5 (1107 views)
Re: word count [In reply to] Can't Post

Excellent Point Japhy,

He's right, he also has told me about this url

Before and it's a very good site for doing perl research. Maybe you should check that out when you get stuck on something that your pretty sure is a common problem. Also at a faq is listed there. It's excellent.



Nov 7, 2000, 1:12 AM

Post #3 of 5 (1107 views)
Re: word count [In reply to] Can't Post

Hi raven,

Use the length(); function. It returns the length of characters of a string.

if (length($word) =< 4)



Nov 7, 2000, 4:13 AM

Post #4 of 5 (1107 views)
Re: word count [In reply to] Can't Post

As sleuth has pointed out, there's a builtin method for this. Perl is less of a scripting language (like sh, for instance, where the script consists of calling other programs) than a programming language (like C, where the functions exist in the language itself).

If you find yourself calling a lot of external programs for things that seem like they should be really simple to you (like finding the length of a string), you should rethink your strategy, and probably check the Perl function documentation, and see if there's a builtin function that does what you need. Or, check the Perl FAQ list, which is an extensive compilation of frequently asked questions about topics pertaining to Perl programming.

Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher


Nov 7, 2000, 7:47 PM

Post #5 of 5 (1107 views)
Re: word count [In reply to] Can't Post

Thanx for the help, I know this was not the ideal way of trying to write the script but I did not have much of a choice, for certain reasons it had to be more in the form of a bash script. I appreciate all the help.
Thanx Raven


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives