Solved

Perl roockie! please help

Posted on 2002-07-14
6
164 Views
Last Modified: 2010-03-05
Hello, this is my first day using perl and site experts-exchange.com to.

I making a single perl script to read from a text file and then ask for an action.  
chop ($number);
if ($number eq 4){
     print "Cool.\n\n";
     }
if ($number ge 5){
     print "That's to much!\n\n";
     }
else {
     print "That's Nothing";
     }

If I put 3 or less it says  "That's Nothing" (OK)
If I put 5 or more it says  "That's to much!"; (OK)

But why if I set eq 4 says "Cool." when I put 4 it says
"Cool."   - and also -   "That's Nothing"

0
Comment
Question by:Silentbob19
  • 3
  • 3
6 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 7152998
my $number = <STDIN>;
chomp $number;
if( $number == 4 ){
    print "Cool.\n\n";
}elsif( $number >= 5 ){
    print "That's to much!\n\n";
}else{
   print "That's Nothing"
}
0
 

Author Comment

by:Silentbob19
ID: 7153012
why do you use "my"?
And why chomp and not chop?

There's a diference if a use it like
$number = <STDIN>;
chop ($number);
0
 

Author Comment

by:Silentbob19
ID: 7153020
Also if I put 125 for ex. It't thinks it is 1 and not 125

Sorry about my english... I speak spanish.
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 84

Expert Comment

by:ozo
ID: 7153025
I used my so the code would pass "use strict;"

chomp is safer in that it only removes $/
0
 
LVL 84

Expert Comment

by:ozo
ID: 7153029
Also if I put 125 for ex. It't thinks it is 1 and not 12

 ge is a string comnpare, use >= to compare numbers
0
 

Author Comment

by:Silentbob19
ID: 7153052
Thank's so mucho... This is my first day on perl... I have to learn  a lot.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
hard perl script 16 158
pattern matching in perl 2 107
Perl 101 11 81
Removing file extension within a file. 4 98
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question