--
__________________________________________________________________________
Tablua Materna combusta est! Sum in modo pessimo!
My motherboard fried! I'm in a pessimal
mode!
Gary P. Thompson II--gt...@nyx.net
Heh, nice page, Gary. Good job.
-Brandon
Thanks.
>It's a collection of all the self-reproducing programs I've been
>able to find.
You left out my favorite one:
open+0;print<0>
Also, I don't think Jef Pinyan nvented the one you credited to him.
Also, you might want to look at mine, which is at
This is a cheat, by the way.
MD> In article <75trs9$p9o$1...@monet.op.net>, Mark-Jason Dominus
MD> <m...@op.net> wrote:
>> open+0;print<0>
MD> This is a cheat, by the way.
i wonder if a perl quine must be runnable with -e to filter out
cheats. i am sure some use <DATA> but other than that they should run
under -e and then you can't get at $0 or stdin.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---------------------- Perl, Internet, UNIX Consulting
u...@sysarch.com ------------------------------------ http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
Here's another "cheat":
#!/usr/local/bin/perl -w
print `cat $0`;
Abigail
http://www.ionet.net/~timtroyr/funhouse/beer.html
i though the existing perl entry sucked, here it is:
$nBottles = $ARGV[0];
$nBottles = 100 if $nBottles eq '' || $nBottles < 0;
foreach (reverse(1 .. $nBottles)) {
$s = ($_ == 1) ? "" : "s";
$oneLessS = ($_ == 2) ? "" : "s";
print "\n$_ bottle$s of beer on the wall,\n";
print "$_ bottle$s of beer,\n";
print "Take one down, pass it around,\n";
print $_ - 1, " bottle$oneLessS of beer on the wall\n";
}
print "\n*burp*\n";
i was embarrassed that our lovely language was so poorly represented,
so i wrote a (almost) one liner. other than the arg handling it is one
statement. so my xmas eve challenge to all you non-christians and
get-a-lifers is to write your favorite version to generate this ditty.
the hardest part is getting the 's' right. any other short ways of
having 1 or 0 's' based on a boolean are welcome.
enjoy,
uri
$n = shift || 99 ;
print <<BEER while $n ;
$n bottle@{[$s='s'x($n>1)]} of beer on the wall, $n bottle$s of beer!
Take one down and pass it around,
@{[--$n]} bottle@{['s'x($n!=1)]} of beer on the wall!
BEER
Uri Guttman Hacking Perl for Ironbridge Networks
u...@sysarch.com u...@ironbridgenetworks.com
I like this:
$n > 1 && 's'
Gut Jul, Y'all!
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
l...@hpl.hp.com
> the hardest part is getting the 's' right. any other short ways of
> having 1 or 0 's' based on a boolean are welcome.
For what it's worth...
$i = @ARGV ? shift : 99;
my @a= qw/bottle of beer on the wall/;
print <<END while $i;
$i $a[0]${\($i<2?'':'s')} @a[1..5],
$i $a[0]${\($i<2?'':'s')} @a[0..2]
Take one down and pass it around,
${\--$i} $a[0]${\($i<2?'':'s')} @a[1..5]
END
Merry Whatever,
Andre
Ah, shoot. Line 5 is supposed to read,
$i $a[0]${\($i<2?'':'s')} @a[1,2]
Andre
> $n = shift || 99 ;
> print <<BEER while $n ;
> $n bottle@{[$s='s'x($n>1)]} of beer on the wall, $n bottle$s of beer!
> Take one down and pass it around,
> @{[--$n]} bottle@{['s'x($n!=1)]} of beer on the wall!
>
> BEER
How about this?
$_=shift||99;$b='"$_ bottle$s[$_==1] of beer"';$w=' on the wall';@s='s';print
eval$b,"$w, ",eval$b,"!\nTake one down, pass it around,\n",eval'$_--;'.$b,$w,
"!\n\n"while$_
More statements, but shorter overall. Also, don't run it with warnings on.
(Making it warnings-safe requires six more characters! :-)
--
_ / ' _ / - aka - r...@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chip...@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
0 bottle of beer? Uri had this one right! Burp...
What about 0?
I drank 0 bottle of beer.
:-)
Happy Vacation!
--Matthew
MB> In article <MPG.10ec86c6d...@nntp.hpl.hp.com>, l...@hpl.hp.com
MB> says...
MB> => In article <39hful2...@ibnets.com> on 24 Dec 1998 16:01:28 -0500,
MB> => Uri Guttman <u...@ibnets.com> says...
MB> => ...
MB> => > the hardest part is getting the 's' right. any other short ways of
MB> => > having 1 or 0 's' based on a boolean are welcome.
MB> =>
MB> => I like this:
MB> =>
MB> => $n > 1 && 's'
MB> What about 0?
MB> I drank 0 bottle of beer.
if you look at my original code, i use a different boolean for the last
line.
$n != 1 && 's' would work for that.
RJK> Uri Guttman <u...@ibnets.com> wrote:
>> $n = shift || 99 ;
>> print <<BEER while $n ;
>> $n bottle@{[$s='s'x($n>1)]} of beer on the wall, $n bottle$s of beer!
>> Take one down and pass it around,
>> @{[--$n]} bottle@{['s'x($n!=1)]} of beer on the wall!
>>
>> BEER
RJK> How about this?
RJK> $_=shift||99;$b='"$_ bottle$s[$_==1] of beer"';$w=' on the
RJK> wall';@s='s';print eval$b,"$w, ",eval$b,"!\nTake one down, pass
RJK> it around,\n",eval'$_--;'.$b,$w, "!\n\n"while$_
RJK> More statements, but shorter overall. Also, don't run it with
RJK> warnings on. (Making it warnings-safe requires six more
RJK> characters! :-)
well, i wasn't trying for the actual shortest one but why not? i was
minimally replacing the crap i saw on the site with something much more
perlish.
i could shrink mine with some text merging too but i didn't do that in
the first pass except for the 's' in the first line. i will play with
mine some more.
RJK> How about this?
RJK> $_=shift||99;$b='"$_ bottle$s[$_==1] of beer"';$w=' on the
RJK> wall';@s='s';print eval$b,"$w, ",eval$b,"!\nTake one down, pass
RJK> it around,\n",eval'$_--;'.$b,$w, "!\n\n"while$_
i reduced mine to the same length (i think) as yours. i stole your @s
trick which is cool. but i like my style better as i don't need no
stinkin' evals!
$n=shift||99;@s='s';$o=' on the wall';print<<B while$n
@{[$b="$n bottle$s[$n<1] of beer"]}$o, $b!
Take one down and pass it around,
${\--$n} bottle$s[$n==1] of beer$o!
B
i played with the here doc and tried a quoted string but it comes out
about the same. i tried to factor out the other common text (bottle, of
beer) but the overhead was longer than a copy.
Here's one that prints 'no more bottles of beer' at the end:
#!/usr/local/bin/perl -wis
use strict; chomp $/;
print map {<<EOT
$_ Bottle$^I of beer on the wall,
$_ bottle$^I of beer,
Take one down and pass it around,
${\do {($^I,$/) = ($/,$^I) if -- $_ < 2; $_ || "no more"}} bottle$^I of beer.
EOT
} reverse 1 .. shift || 99;
__END__
Abigail
> 0 bottle of beer? Uri had this one right! Burp...
I wasn't aware that "0 bottles" was plural. :-/
I reckon ma English ain't no better than ma Perl.
Andre
A> Here's one that prints 'no more bottles of beer' at the end:
A> #!/usr/local/bin/perl -wis
A> use strict; chomp $/;
A> print map {<<EOT
A> $_ Bottle$^I of beer on the wall,
A> $_ bottle$^I of beer,
A> Take one down and pass it around,
A> ${\do {($^I,$/) = ($/,$^I) if -- $_ < 2; $_ || "no more"}} bottle$^I of beer.
A> EOT
A> } reverse 1 .. shift || 99;
A> __END__
nice one abby, but you forgot the 'on the wall' at the end of the last
line. but the swap at 1 is cute. so this gets an B-.
and it is much longer than ronald's or my solution.
:-)
AL> In article <MPG.10eca1c54...@nntp.hpl.hp.com>, l...@hpl.hp.com
AL> (Larry Rosler) wrote:
>> 0 bottle of beer? Uri had this one right! Burp...
AL> I wasn't aware that "0 bottles" was plural. :-/
AL> I reckon ma English ain't no better than ma Perl.
well, both languages are melanges of several others without any rigorous
rules. that is why both are so rich and expressive as well as
maddeningly tricky and frustrating.
compare to german and c++!
> >>>>> "RJK" == Ronald J Kimball <r...@linguist.dartmouth.edu> writes:
>
> RJK> How about this?
>
> RJK> $_=shift||99;$b='"$_ bottle$s[$_==1] of beer"';$w=' on the
> RJK> wall';@s='s';print eval$b,"$w, ",eval$b,"!\nTake one down, pass
> RJK> it around,\n",eval'$_--;'.$b,$w, "!\n\n"while$_
>
> i reduced mine to the same length (i think) as yours. i stole your @s
> trick which is cool. but i like my style better as i don't need no
> stinkin' evals!
Yeah, but I don't need no stinkin' expression interpolation via
dereferencing!
I did try to reduce the number of evals, but it just made the code
longer. :-O
> $n=shift||99;@s='s';$o=' on the wall';print<<B while$n
> @{[$b="$n bottle$s[$n<1] of beer"]}$o, $b!
^^^^
$n==1
> Take one down and pass it around,
> ${\--$n} bottle$s[$n==1] of beer$o!
>
> B
1 bottles of beer on the wall, 1 bottles of beer!
Take one down and pass it around,
0 bottles of beer on the wall!
RJK> Uri Guttman <u...@sysarch.com> wrote:
>> $n=shift||99;@s='s';$o=' on the wall';print<<B while$n
>> @{[$b="$n bottle$s[$n<1] of beer"]}$o, $b!
RJK> ^^^^
RJK> $n==1
my last version fixed that but i must have posted one i was still
playing with. i was testing and cutting and pasting all at once with no
coherency since i was following the song lyrics! :-) burp!!!
was just like a boston pm meeting.
>i was embarrassed that our lovely language was so poorly represented,
>so i wrote a (almost) one liner. other than the arg handling it is one
>statement. so my xmas eve challenge to all you non-christians and
>get-a-lifers is to write your favorite version to generate this ditty.
>the hardest part is getting the 's' right. any other short ways of
>having 1 or 0 's' based on a boolean are welcome.
Use Lingua::EN::Inflect!
-----------cut-----------cut-----------cut-----------cut-----------cut----------
use Lingua::EN::Inflect 'inflect';
$n=shift||99 and print inflect<<BURP while $n;
NO(bottle of beer,$n) on the wall, NO(bottle of beer,$n)!
Take one down, pass it around,
NO(bottle of beer,@{[--$n]}) on the wall.
BURP
-----------cut-----------cut-----------cut-----------cut-----------cut----------
Damian
If you want to strive for realism, then let's try to duplicate the
Expect entry from http://www.ionet.net/~timtroyr/funhouse/beer.html.
Don't read the comments at the top of it, though. You really have to
run this to appreciate it.
I started playing around with it, but was having trouble with printing
one letter at a time on my win32 system so I have (temporarily) given up
on posting my copy of it for Uri's challenge. Perhaps someone else
would like to give it a go.
I think Perl hackers should be able to make it even more human-like in
less code (although I get the impression that one would need to 'use
Expect;').
--
Rick Delaney
rick.d...@shaw.wave.ca
Rather than a one-liner, here's a production-ready, strict-compliant
version, featuring an abysmally lazy approach to pluralization:
#!/usr/bin/perl -w
# beer - prints out the '99 bottles of beer' song.
# Craig Berry (19990104)
use strict;
my $botCnt = shift || 99;
my $beer = '%d bottle%s of beer';
my $wall = "$beer on the wall";
my $take = 'Take one down, pass it around,';
my @plural = ('s', '', ('s') x ($botCnt - 1));
for (my $newCnt = $botCnt - 1;
$botCnt > 0;
$botCnt = $newCnt--) {
printf "$wall,\n$beer!\n$take\n$wall!\n\n",
($botCnt, $plural[$botCnt]) x 2,
$newCnt, $plural[$newCnt];
}
--
| Craig Berry - cbe...@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| "The hills were burning, and the wind was raging; and the
clock struck midnight in the Garden of Allah."