[Wellington-pm] comparison and assignment: insignificant optimisation

Kent Fredric kentfredric at gmail.com
Mon Jun 16 04:13:19 PDT 2014


You can do it with a temporary variable *without* adding lines of code.

In fact, this way of doing it will reduce your lines of code =)


sub max_length {
  my @list = @_;

  my $current_max;
  foreach my $item (@list) {
      next unless ( my $len = length($item) ) > $current_max;
      $current_max = $len;
  }
  return $current_max;
}

Granted you need to have a little more brain power active to parse what is
going on there.
-- 
Kent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/wellington-pm/attachments/20140616/164ee2c8/attachment.html>


More information about the Wellington-pm mailing list