CLOSE

A possible solution for the sign.pl program is as follows:

  1. #!/usr/bin/perl
  2.  
  3. # sign.pl - solution for exercise
  4.  
  5. use warnings;
  6. use strict;
  7.  
  8. my $number;
  9.  
  10. print "enter a number: ";
  11.  
  12. $number = <>;
  13.  
  14. if ($number < 0)
  15. {
  16. print "Your number is negative\n";
  17. }
  18. elsif ($number > 0) # use "elsif" here
  19. {
  20. print "Your number is positive\n";
  21. }
  22. else # not positive or negative
  23. {
  24. print "Your number is zero\n";
  25. }
  26.  
  27. # note that a non-numeric entry will be interepreted as zero
  28.  

CLOSE