[Omaha.pm] quick n dirty rand()

Jay Hannah jhannah at omnihotels.com
Thu Jun 9 16:04:16 PDT 2005


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)];

Syntax stolen from

  http://www.rollmop.org/oneliners/perl.html

j




More information about the Omaha-pm mailing list