in reply to Re: Match nothing in grep { ! // }
in thread Match nothing in grep { ! // }

I'm writing a scraper and sometimes I need to exclude some data. As I said, doing:

$css->{xlink} //= ' ';
works in this case but it just doesn't seem like the right way to do this.

@{$ret->{link}} = grep { ! /$css->{xlink}/ } map { $_->{href} } $dom-> +find($css->{link})->each if ($css->{link});

Replies are listed 'Best First'.
Re^3: Match nothing in grep { ! // }
by McA (Priest) on Mar 14, 2013 at 09:21 UTC

    IMHO my post should have helped you as it showed that you can extend the expression in the grep codeblock.

    But now we know a little more of your problem and I assume the following: If $css->{xlink} is defined and not empty you want to try a match. The otherwise clause is not obvious to me, but you can change it. E.g.

    grep { $css->{xlink} && ! /$css->{xlink}/ }

    I hope I understood it right.

    McA

Re^3: Match nothing in grep { ! // }
by Anonymous Monk on Mar 14, 2013 at 09:58 UTC

    I'm writing a scraper and sometimes I need to exclude some data. ...

    Well, that much (your desire) was clear from your original post, but its still not a question :)

    If you want to filter based on a regex, and a space isn't adequate, what is adequate?

    ?? if( sometingTrue ){ grep filter } else { no grep filter }

    Or were you after what McA wrote?