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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
printing largest number of two different ones.

 



InternetDominus
New User

Feb 22, 2016, 5:39 PM

Post #1 of 3 (1353 views)
printing largest number of two different ones. Can't Post


Code
#!D:/perl/perl/bin/perl.exe 
# Script name = exercisechap2.pl

use strict;
use warnings;
use diagnostics;
use CGI::Carp 'fatalsToBrowser';
use CGI qw(-debug);
print "Content-type: text/html\n\n";

my $number1 = 50;
my $number2 = 80;

if ($number1 > $number2)
{print $number1 is greater than $number2}
else
{print $number2 is greater than $number1}


Hello, above is the script I am using to get the largest number between $number1, and $number2. Can someone tell me why I get this error below? I am using 80 as a number with no single or double quotes, but error still says that it is a string, why?

##########
Software error:

Can't use string ("80") as a symbol ref while "strict refs" in use at D:/wamp/www/perl/exercisechap2.pl line 18.
##########

Thanks!


Laurent_R
Veteran / Moderator

Feb 23, 2016, 3:04 AM

Post #2 of 3 (1343 views)
Re: [InternetDominus] printing largest number of two different ones. [In reply to] Can't Post

Hi, you must print strings. Try to change the last four lines to this:


Code
if ($number1 > $number2) { 
print "$number1 is greater than $number2\n";
} else {
print "$number2 is greater than $number1\n";
}



InternetDominus
New User

Feb 25, 2016, 3:28 PM

Post #3 of 3 (1327 views)
Re: [Laurent_R] printing largest number of two different ones. [In reply to] Can't Post

I missed that!
Thanks!

 
 


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

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