I am probably to late to be of any help, but I can add one significant detail. I find the logic more intuitive if we initialize the result with a large negative number. You can get the largest possible number from POSIX, but with only a small loss in generality, we can choose any number that is larger than any we expect in our input.
se strict;
use warnings;
#use POSIX qw(DBL_MAX);
my $x = $ARGV[0] // -11;
my $y = $ARGV[1] // -13;
my $z = $ARGV[2] // -17;
#my $MAX_NEG = -DBL_MAX;
my $MAX_NEG = -99999; # Better to use DBL_MAX from POSIX
my $max = $MAX_NEG;
if ( $x % 2) {
$max = $x ;
}
if ( $y % 2 and $y > $max ) {
$max = $y ;
}
if ( $z % 2 and $z > $max ) {
$max = $z ;
}
die "There are no odd values.\n" if ($max == $MAX_NEG) ;
print "the largest odd number is $max.\n";
Note: I took the freedom to use the disallowed operator (//) to override the default values of $x, $y, and $z with values from the command line. I do not consider this part of the solution.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.