[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Omaha.pm] quick n dirty rand()



On Thu, Jun 09, 2005 at 06:04:16PM -0500, Jay Hannah (jhannah@omnihotels.com) wrote:
> 
> Before
> 
>   my $rand = int(rand(3))+1;
>   my $imagename = "sean.jpg";
>   $imagename = "jay.jpg"      if ($rand == 2);
>   $imagename = "airplane.jpg" if ($rand == 3);
> 
> After
> 
>   my $imagename = ("sean.jpg", "jay.jpg", "airplane.jpg")[(int rand 3)];

Better yet:

my @images = qw( sean.jpg jay.jpg airplane.jpg );
my $random_image = $images[rand @images];

-- 
Andy Lester => andy@petdance.com => www.petdance.com => AIM:petdance