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

[Omaha.pm] code reduction :)




:)

j


-------
Before
-------
  my $pages = {
    "RR"      => [ "RR1","RR1_1","RR1_2","RR2","RR_more_rooms" ],
    "RR1"     => [ "RR1_2","RR_more_rooms" ],
  };

  my $destinations = $pages->{$pagesrc};
  if (not defined $destinations) {
     return 0;
  }
  my $found=0;
  foreach my $dst (sort @{$destinations}) {
    if ($pagedst eq $dst or $pagesrc eq $pagedst)  {
      $found++;
      last;
    }
  }
  if (!$found) {
     return 0;
  }
  return 1;


-------
After
-------
  return 0 unless ($pagesrc && $pagedst);
  return 1 if ($pagesrc eq $pagedst);

  my $pages = {
    "RR"      => [ "RR1","RR1_1","RR1_2","RR2","RR_more_rooms" ],
    "RR1"     => [ "RR1_2","RR_more_rooms" ],
  };

  return grep { $_ eq $pagedst } @{$pages->{$pagesrc}};