prospect has asked for the wisdom of the Perl Monks concerning the following question:
So I am messing around with subroutines, I got this piece of code running last week but now when I return to it, it's giving me syntax error on line 18. I compared the sources I got it from and the syntax used in those cases and I just can't see it. I wanted to make a little exercise where the user inputs two values, 1 for $fred and 1 for $barney and it would say which value is bigger. But when I run it, it says there is a syntax error on line 18 and I cannot find it :/
sub combo { my $sum = $fred * $barney return $sum; if ($fred > $barney) { $fred; #also why do I have to put another $fred here? It doesn +#'t seem to be part of "if" nor of "else" } else { $barney; } } print "Enter value:"; $fred = <STDIN>; # chomp $fred; print "Enter value:"; $barney = <STDIN>; # chomp $barney;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why am I getting "syntax error at Funcy.pl line 18, near "$barney return" ?
by haukex (Archbishop) on Jul 24, 2017 at 08:40 UTC | |
by prospect (Acolyte) on Jul 24, 2017 at 08:42 UTC | |
by Laurent_R (Canon) on Jul 24, 2017 at 09:00 UTC | |
by prospect (Acolyte) on Jul 24, 2017 at 09:06 UTC | |
|
Re: Why am I getting "syntax error at Funcy.pl line 18, near "$barney return" ?
by AnomalousMonk (Archbishop) on Jul 24, 2017 at 14:32 UTC |