nysus has asked for the wisdom of the Perl Monks concerning the following question:
I'm stuck on what I think should be a simple problem. I want to filter out elements from an array. I don't know if they array contains strings or numbers or both. And I don't know if the value I want to filter out is a string or number:
my $string_or_number; my @filtered = grep { $string_or_number ne $_ } @strings_or_numbers;
What's the best way to accomplishing this without throwing an error if the wrong equality operator is used?
$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Filtering array of strings and numbers
by Athanasius (Cardinal) on Apr 29, 2016 at 15:39 UTC | |
by stevieb (Canon) on Apr 29, 2016 at 15:46 UTC | |
by AnomalousMonk (Archbishop) on Apr 29, 2016 at 16:32 UTC | |
by Laurent_R (Canon) on Apr 29, 2016 at 17:01 UTC | |
by AnomalousMonk (Archbishop) on Apr 29, 2016 at 18:26 UTC | |
by syphilis (Archbishop) on Apr 30, 2016 at 01:49 UTC | |
by msh210 (Monk) on May 02, 2016 at 17:36 UTC | |
|
Re: Filtering array of strings and numbers
by BillKSmith (Monsignor) on Apr 29, 2016 at 20:14 UTC | |
by graff (Chancellor) on Apr 30, 2016 at 17:04 UTC | |
|
Re: Filtering array of strings and numbers
by dulwar (Monk) on Apr 29, 2016 at 19:50 UTC |