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.

Bill

In reply to Re: John Guttag's book - 2nd exercise. My attempt in Perl. by BillKSmith
in thread John Guttag's book - 2nd exercise. My attempt in Perl. by pritesh_ugrankar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.