Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

too much free time

by Anonymous Monk
on Mar 30, 2014 at 19:51 UTC ( #1080323=perlmeditation: print w/ replies, xml ) Need Help??

#!/usr/bin/perl -w use strict; use Email::Send; use Email::Send::Gmail; use Email::Simple::Creator; my $to = $ARGV[0]; my $from = $ARGV[1]; my $pass = $ARGV[2]; my $prog = (split /\//, $0)[-1]; die "\n\tusage: $prog to from pass\n" if(!$to || !$from || !$pass); for(my $i=99; $i>0; $i--){ my $y = $i - 1; my $bottles = 'bottle'; $bottles .= 's' if(!($i == 1)); my $line = "$i $bottles of beer on the wall, " . "$i $bottles of beer, take one down " . "pass it around, $y bottles of beer " . " on the wall.\n"; my $email = Email::Simple->create( header => [ From => $from, To => $to, Subject => '', ], body => $line, ); my $sender = Email::Send->new( { mailer => 'Gmail', mailer_args => [ username => $from, password => $pass, ] } ); print $line, "\n"; eval { $sender->send($email) }; die "Error sending email: $@" if $@; }

Comment on too much free time
Download Code
Re: too much free time
by soonix (Deacon) on Mar 30, 2014 at 21:02 UTC
      very nice! this one was written to blow up someones phone :)
Re: too much free time
by sundialsvc4 (Monsignor) on Mar 31, 2014 at 00:34 UTC

    And it’s a ver-r-r-r-y slow Sunday night on PerlMonks, folks ...

Re: too much free time
by eyepopslikeamosquito (Canon) on Mar 31, 2014 at 10:01 UTC

    From Drunk on golf: 99 Bottles of Beer:

    The article capitalizes on the tendency of popular songs to evolve from long and content-rich ballads to highly repetitive texts with little or no meaningful content. Knuth writes that "our ancient ancestors invented the concept of refrain" to reduce the space complexity of songs, which becomes crucial when a large number of songs is to be committed to one's memory ... more ingenious approaches yield songs of complexity O(logN), a class known as "m bottles of beer on the wall".

    -- The Complexity of Songs by Donald Knuth (1977)

    While the affection for this song among computer programmers may have begun in 1977, with the publication of Knuth's seminal paper, it didn't become wildly popular until 1994, when some nitwit posted the entire lyrics of the song to a humour mailing list, provoking a BASIC version to be written:

    10 REM BASIC Version of 99 Bottles of beer 20 FOR X=100 TO 1 STEP -1 30 PRINT X;"Bottle(s) of beer on the wall,";X;"bottle(s) of beer" 40 PRINT "Take one down and pass it around," 50 PRINT X-1;"bottle(s) of beer on the wall" 60 NEXT
    to "save mailing list bandwidth". It snowballed from there until today we can now choose from more than 1400 programming language variations.

    Over the years, many different Perl solutions have been proposed. On December 25 1998, for instance, Damian Conway composed a version using his Lingua::EN::Inflect module:

    use Lingua::EN::Inflect 'inflect'; $n=shift||99; 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

    Oh, and here's a version using Acme-EyeDrops:

    ''=~( '(?{' .('`' |'%') .('[' ^ +'-') .('`' |'!') .('`' |',') .'"'. ' +\\$' .'==' .('[' ^'+') .('`' |'/') . +('[' ^'+') .'||' .(';' &'=') .(';' & +'=') .';-' .'-'. '\\$' .'=;' .('[' ^ +'(') .('[' ^'.') .('`' |'"') .('!' ^ +'+') .'_\\{' .'(\\$' .';=('. '\\$=|' ."\|".( '` +'^'.' ).(('`')| '/').').' .'\\"'.+( '{'^'['). ('`'|'"') .(' +`'|'/' ).('['^'/') .('['^'/'). ('`'|',').( '`'|('%')). '\\".\\"'.( '['^ +('(')). '\\"'.('['^ '#').'!!--' .'\\$=.\\"' .('{'^'['). ('`'|'/').( '`'| +"\&").( '{'^"\[").( '`'|"\"").( '`'|"\%").( '`'|"\%").( '['^(')')). '\\" +).\\"'. ('{'^'[').( '`'|"\/").( '`'|"\.").( '{'^"\[").( '['^"\/").( '`'| +"\(").( '`'|"\%").( '{'^"\[").( '['^"\,").( '`'|"\!").( '`'|"\,").( '`'| +(',')). '\\"\\}'.+( '['^"\+").( '['^"\)").( '`'|"\)").( '`'|"\.").( '['^ +('/')). '+_,\\",'.( '{'^('[')). ('\\$;!').( '!'^"\+").( '{'^"\/").( '`'| +"\!").( '`'|"\+").( '`'|"\%").( '{'^"\[").( '`'|"\/").( '`'|"\.").( '`'| +"\%").( '{'^"\[").( '`'|"\$").( '`'|"\/").( '['^"\,").( '`'|('.')). ','. +(('{')^ '[').("\["^ '+').("\`"| '!').("\["^ '(').("\["^ '(').("\{"^ '[') +.("\`"| ')').("\["^ '/').("\{"^ '[').("\`"| '!').("\["^ ')').("\`"| '/') +.("\["^ '.').("\`"| '.').("\`"| '$')."\,".( '!'^('+')). '\\",_,\\"' .'!' +.("\!"^ '+').("\!"^ '+').'\\"'. ('['^',').( '`'|"\(").( '`'|"\)").( '`'| +"\,").( '`'|('%')). '++\\$="})' );$:=('.')^ '~';$~='@'| '(';$^=')'^ '['; +$/='`';

      Of course, nowadays I'd write it in Perl 6, taking advantage of constants, aliasing, lazy mappings over infinite lists, string interpolation of code, automatic command-line interfaces, parameter defaults, countdown sequences, and indentable heredocs:

      constant @bottles_of_beer := ('No', 1, 2...*).map(->$n{"$n bottle{'s' if $n ne 1} of beer"}); sub MAIN(Int $max = 99) { for $max...1 -> $n { say qq:to<BURP!> @bottles_of_beer[$n] on the wall, @bottles_of_beer[$n]. Take one down, pass it around, @bottles_of_beer[$n-1] on the wall. BURP! } }

      ;-)

      Damian

        Maybe we should be spending our time deciding what to call "Perl 6," since it obviously isn't "Perl." At best, it's a language that adopted a few keywords, like my and use, but it bears no resemblance (nor compatibility) at all to its erstwhile namesake. On a boring night, maybe that would be a more productive thing to think about than bottles of beer ... or, maybe not.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://1080323]
Approved by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2014-07-23 04:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (133 votes), past polls