Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: PCRE help with negative match

by sundialsvc4 (Monsignor)
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2014-04-19 01:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (475 votes), past polls