Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^2: grep with looped tests

by RichardK (Vicar)
on Jun 06, 2014 at 15:57 UTC ( #1089051=note: print w/ replies, xml ) Need Help??

in reply to Re: grep with looped tests
in thread grep with looped tests

Similarly, using first from List::Util to short circuit the inner loop when you match a line :)

use v5.18; use warnings; use List::Util 'first'; use Data::Dumper; my @data = 0..10; my @re = (3,7,9); my @res = grep {my $line = $_; !defined first {$line =~ $_} @re } @dat +a; say Dumper(\@res);

Comment on Re^2: grep with looped tests
Download Code
Replies are listed 'Best First'.
Re^3: grep with looped tests
by LanX (Chancellor) on Jun 06, 2014 at 16:03 UTC
    Ah I always forget that List::Util (which is core) has now any , too!

    (I'm still hooked on List::MoreUtils , see next answer :)

    > my @res = grep {my $line = $_; !defined first {$line =~ $_} @re } @data;

    But I think you'd certainly prefer any over first to avoid !defined ! :)


    though first was and any wasn't part of my 5.10 distribution!

    Cheers Rolf

    (addicted to the Perl Programming Language)

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2015-11-26 13:17 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (699 votes), past polls