Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: How to make sure no elements from @array are inside $scalar

by Loops (Curate)
on Nov 14, 2014 at 14:14 UTC ( #1107205=note: print w/replies, xml ) Need Help??

in reply to How to make sure no elements from @array are inside $scalar

Lots of ways to tackle it. Here's one that's too convoluted...

my $text = 'f000124_90181234_dp'; my $sites = [ '018', '324' ]; print "$text To be removed" unless $text=~/_9(...)/,{map{$_,1}@$sites}->{$1};

But using List::Util is better.

use List::Util qw(none); print "$text To be removed" if $text=~/_9(...)/,none {$1 eq $_} @$sites;

Replies are listed 'Best First'.
Re^2: How to make sure no elements from @array are inside $scalar
by tadegenban (Novice) on Nov 15, 2014 at 08:55 UTC

    Can I use

     $text=~/_9(...)/ and none {$1 eq $_} @$sites

    instead of

     $text=~/_9(...)/,none {$1 eq $_} @$sites

    here ?

    What's the difference between 'and' and 'comma' here

      Yes, you can use "and" to much the same effect in this case. In fact it would stop a warning if the match failed and $1 was left undefined. And that's because the comma operator does not short circuit as "and" does; both expressions will be evaluated whether the first is true or false. But it can be useful.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2022-05-17 18:17 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (68 votes). Check out past polls.