LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-08-2004, 02:13 PM   #1
Seventh
Member
 
Registered: Dec 2003
Location: Boston, MA
Distribution: Redhat / Debian
Posts: 269

Rep: Reputation: 30
Quick perl question using length


Code:
print "Type here: ";
$module = <STDIN>;
chomp($module);

    if (length $module) < 8; {
        print "less";
    } else {
       print "more"; }
}
This is giving me errors aplenty. All I'm looking to do is count the characters in whatever the inputted word is, and then if it's more or less than eight, print which.

/scratches head

Last edited by Seventh; 09-08-2004 at 02:15 PM.
 
Old 09-08-2004, 02:29 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Try using:
if (length($module) < 8); {
 
Old 09-08-2004, 02:31 PM   #3
Seventh
Member
 
Registered: Dec 2003
Location: Boston, MA
Distribution: Redhat / Debian
Posts: 269

Original Poster
Rep: Reputation: 30
That was it. Thanks!
 
Old 09-08-2004, 02:44 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally posted by david_ross
Try using:
if (length($module) < 8); {
With semi-colon?


Cheers,
Tink
 
Old 09-08-2004, 04:29 PM   #5
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
You can also short it :
Code:
print "Type here: ";
$module = <STDIN>;
chomp($module);
print length $module < 8 ? "less" : "more";
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
quick perl question eagle683 Programming 7 08-01-2005 03:28 AM
quick perl question eagle683 Programming 2 07-05-2005 02:28 PM
finding array length from a reference (in Perl) lowpro2k3 Programming 1 06-22-2005 04:49 PM
perl matching *-length strs towlie Programming 2 07-21-2004 08:13 PM
finding the length of an array in perl acid_kewpie Programming 5 09-25-2002 10:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration