[Cialug] Shotgun?

Renegade Muskrat dramaley at spatulacity.cx
Sun Aug 14 20:22:45 CDT 2005


What was the "for" loop for on your version of the script? Just as an 
exercise i thought i'd see how small i could get a perl program that 
picks a weekday and prints it. It is below. If anyone can think of a 
way to do it even smaller, let me know.

#!/usr/bin/perl -w
print "",qw(Monday Tuesday Wednesday Thursday Friday)[5*rand],"\n"

At 09:59 PM 8/12/2005 -0500, you wrote:
 >Or, just choose the day randomly.  perl can do this quite nicely:
 >
 >#!/usr/bin/perl -w
 >%days = (0 => 'wednesday',
 >        1 => 'friday',
 >        2 => 'thursday',
 >        3 => 'monday',
 >        4 => 'tuesday');
 >for($i=rand(100); $i > 0; $i--)
 >{
 >  $day = int(rand(5));
 >  system('clear');
 >  print( $days{$day} . "\n");
 >}
                                                -- Dan
   --------------------------------------------------------------------
             "I'm still sane on three planets and two moons."
   --------------------------------------------------------------------
       Daniel Ramaley                  3118 Cottage Grove Ave Apt 8
       dramaley at spatulacity dot cx        Des Moines, Iowa 50311
       http://www.spatulacity.cx/                    (515) 271-5233
   --------------------------------------------------------------------
        WARNING: REDISTRIBUTION OF THIS MESSAGE MAY BE IN
                 VIOLATION OF APPLICABLE COPYRIGHT LAWS.
                 THIS MESSAGE NOT GUARANTEED Y-TO-K COMPLIANT.



More information about the Cialug mailing list