• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 190
  • Last Modified:

Perl roockie! please help

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
Silentbob19
Asked:
Silentbob19
  • 3
  • 3
1 Solution
 
ozoCommented:
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
 
Silentbob19Author Commented:
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
 
Silentbob19Author Commented:
Also if I put 125 for ex. It't thinks it is 1 and not 125

Sorry about my english... I speak spanish.
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
ozoCommented:
I used my so the code would pass "use strict;"

chomp is safer in that it only removes $/
0
 
ozoCommented:
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
 
Silentbob19Author Commented:
Thank's so mucho... This is my first day on perl... I have to learn  a lot.
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now