Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Filtering array of strings and numbers

by dulwar (Monk)
on Apr 29, 2016 at 19:50 UTC ( [id://1161906]=note: print w/replies, xml ) Need Help??


in reply to Filtering array of strings and numbers

Hi nysus

It's not clear from the question, but if you actually need to filter based on numerical equality, in the case where both the $string_or_number and the array element are numbers, then you can use the following:

use Scalar::Util 'looks_like_number'; #... my @filtered = grep { defined && $string_or_number ne $_ && !(looks_like_number($_) && looks_like_number($string_or_number) && $string_or_number == $_) } @strings_or_numbers;

That will, for example, filter out elements that are "5" when $string_or_number is "5.0".

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1161906]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-24 00:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found