Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Not bad for a first program ... here is a less redundant version in the interest of helping you learn more:
#!/usr/bin/perl -w use strict; my $beer = abs shift || 99; print how_many($beer), ",\n", how_many($beer), ".\n", "Take one down, pass it around,\n", how_many(--$beer), ".\n\n" while $beer; sub how_many { my $numb = shift; return $numb . ' bottle' . ($numb == 1 ? '' : 's') . ' of beer on the wall' ; }
Instead of asking the user for the number of beers *hic*, the code instead gets the number as a command line argument. If no argument is supplied, it instead uses a default value of 99. Also, it counts down until $beer is a false value instead of until $beer is 0 - hence, we have to take the absolute value of that command line argument lest the user give us a negative value and spin us off into an infinite loop. This version also uses a subroutine and a ternary operator (expr ? true : false), which is just a fancy if-else that is used to avoid spouting out '1 bottles'.

Keep on coding! :)

UPDATE: oops, you are correct mystik - and yes, my vision was blurry last night! :D (typo corrected)


(the triplet paradiddle with high-hat)

In reply to (jeffa) Re: 99 bottles of beer on the Wall by jeffa
in thread 99 bottles of beer on the Wall by legolas

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (5)
    As of 2018-06-24 12:37 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (126 votes). Check out past polls.