develooper Front page | perl.fwp | Postings from May 2003

Re: 99 bottles of beer on the wall

May 24, 2003 22:41
Re: 99 bottles of beer on the wall
Message ID:
Ronald J Kimball wrote:
> Then please consider my more recent version...  :)
> $n=pop||99;sub b{"$n bottle@{[$n!=1&&s=>]} of beer"}print$b=b,$w=' on
> the wall',
> ",\n$b,\nTake one down, pass it around,\n",b($n--),"$w.\n"while$n
> P.S.  Yes, you can save characters by using literal newlines, but
> I find that cheesy, and it makes the code difficult to execute as
> a command line.

And here is the cheesy version of Ron's more recent version, with
output matching exactly the originals of four and a half years ago:

$n=shift||99;sub b{"$n bottle@{[$n!=1&&s=>]} of beer"}
print$b=b,$w=' on the wall',
", $b!
Take one down, pass it around,


which I score at 144 strokes.
(It is debatable whether you should allow pop instead of shift for
the argument; I have stuck with shift for reasons of tradition but
am happy to be out-voted on that one).

/-\ - Yahoo! Mobile
- Check & compose your email via SMS on your Telstra or Vodafone mobile. Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About