[Omaha.pm] we need a 1 liner

Sean Baker pbaker at omnihotels.com
Wed Nov 15 08:03:06 PST 2006


$self->{pools} = grep { $_ > 0 } @{$self->{pools}};



Test script:

#!/usr/bin/perl
my @old = (-1,0,1,2,3,4,5);
@old = grep { $_ > 0 } @old;
foreach (@old) {
  print "$_\n";
}

pbaker at razorbill:~> perl t.pl
1
2
3
4
5

Sean Baker
Software Architect
Omni Hotels

-----Original Message-----
From: omaha-pm-bounces+pbaker=omnihotels.com at pm.org
[mailto:omaha-pm-bounces+pbaker=omnihotels.com at pm.org] On Behalf Of Jay
Hannah
Sent: Tuesday, November 14, 2006 8:22 PM
To: Perl Mongers of Omaha, Nebraska USA
Subject: [Omaha.pm] we need a 1 liner


Can anyone tell me what the 1 liner for this is before Andy does?

:)

j


  my @old = @{$self->{pools}};
  my @new;
  foreach (@old) {
     if (@$_ > 0) {
        push @new, $_;
     }
  }
  $self->{pools} = \@new;


_______________________________________________
Omaha-pm mailing list
Omaha-pm at pm.org
http://mail.pm.org/mailman/listinfo/omaha-pm



More information about the Omaha-pm mailing list