Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: PCRE help with negative match

by sundialsvc4 (Abbot)
on Aug 13, 2013 at 04:30 UTC ( #1049210=note: print w/ replies, xml ) Need Help??

in reply to PCRE help with negative match

Like many others, I do not see an immediately-obvious “bright-line rule” here that could easily be expressed in a regex.   And even if I did, I think that the resulting “solution” would be very, very difficult to maintain over time.

Therefore, if it were me, I would simply split() the string by dashes, then follow this by a series of explicit conditional tests, such as the next unless statements in this snippet:

while (<FILEHANDLE>) { my @pieces = split(',', $_); next unless ($pieces[0] eq '8898'); next unless ($pieces[2] eq 'sdfgh1'); ... # IF WE MAKE IT ALL THE WAY HERE IT'S A GOOD REC DO SOMETHING }

It is, I think, “immediately obvious” what this code is doing, and it is also obvious how to extend it and/or change it without breaking it.   Whereas it is a very difficult thing indeed to have to deal with “clever, efficient” code that “seemed to work okay” at the time that it was written but now rightly shows itself to be a house of cards.   I fear that “regex cleverness” would be nothing but trouble in the long run here.

Comment on Re: PCRE help with negative match
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1049210]
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 2015-10-08 21:33 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (228 votes), past polls