Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1049210]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2017-11-19 22:19 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (282 votes). Check out past polls.