I am trying to filter values in an array using grep (in Perl). My goal is to remove array elements where both the "pending" element is INVALID_APNS and the "token" element is empty
This does not work - it deletes everything. The array contains 0 elements after the rep, but should contain 2.
use constant INVALID_APNS => -1;
@active_connections = (
{
pending => INVALID_APNS,
token=>'123'
},
{
pending => INVALID_APNS,
token=>'123'
},
{
pending => INVALID_APNS,
token=>''
},
);
@active_connections = grep { ($_->{pending} != INVALID_APNS) && ($_->{token} ne '')} @active_connections;
print scalar @active_connections;
What am I doing wrong?