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

Re^3: grep trouble

by LanX (Archbishop)
on Apr 18, 2011 at 08:30 UTC ( #899897=note: print w/replies, xml ) Need Help??


in reply to Re^2: grep trouble
in thread grep trouble

1. > But he's using grep.

Agreed, but he could copy $_ and define fall-backs for edge cases like "". (I'm not sure if he should)

grep { my $pat = ( $_ eq ="" ? EMPTY_PAT : $_ ); $string =~ m/$pat/g } @patterns;

If this gets more complicated he should consider using a function instead of an anonymous block.

2. > I suspect that where he showed us a literal empty string, ...

I suppose he is checking multiple log-files simultaneously for the same matching patterns. By grepping patterns, he is calculating the intersection of all patterns which apply to all files.

> those situations probably warrant a comment in real-world code

That's why I would prefer a special var $PATTERN for this behavior.

Cheers Rolf

UPDATE: what bothers me is not this special behavior of a literally empty match m// but that of "If the PATTERN evaluates to the empty string". IMHO that $pat="";m/$pat/ behavior is difficult to justify.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2018-12-11 12:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many stories does it take before you've heard them all?







    Results (54 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!