[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Omaha.pm] we need a 1 liner
$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@razorbill:~> perl t.pl
1
2
3
4
5
Sean Baker
Software Architect
Omni Hotels
-----Original Message-----
From: omaha-pm-bounces+pbaker=omnihotels.com@pm.org
[mailto:omaha-pm-bounces+pbaker=omnihotels.com@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@pm.org
http://mail.pm.org/mailman/listinfo/omaha-pm