[Cialug] Shotgun?

Nathan C. Smith smith at ipmvs.com
Sun Aug 14 20:35:10 CDT 2005


Is there a perl function that can give day of the week from a number 1-7?

-----Original Message-----
From: Renegade Muskrat [mailto:dramaley at spatulacity.cx] 
Sent: Sunday, August 14, 2005 8:23 PM
To: Central Iowa Linux Users Group
Subject: Re: [Cialug] Shotgun?



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.

_______________________________________________
Cialug mailing list
Cialug at cialug.org
http://cialug.org/mailman/listinfo/cialug


More information about the Cialug mailing list