Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: "Correct" program style questions

by particle (Vicar)
on Oct 24, 2002 at 01:34 UTC ( #207599=note: print w/ replies, xml ) Need Help??


in reply to "Correct" program style questions

i have changed my regular expression style significantly as of late. my list of reasons includes training regex newbies and preparing for perl 6.

here are some of the changes

  • never use a bare regex: // is always written as m//
  • always use the x modifier, and put it up front (more like perl6):
    m/(?x) ((?:blah){3}) ## match w/ capture: blahblahblah /
  • replace all ^ and $ anchors with the safer \A and \z. once bitten, twice shy ;)
    if i read the apocalypses correctly, perl 6's ^ and $ anchors will DWIM better than the current implementation

my take on your regexes might go something like:

... =~ m/(?x) \A ## match w/ capture: one or more alpha, punct, or space posix charac +ters ( [[:alpha:][:punct:][:space:]]+ ) \z /; ## and ... =~ m/(?x) \A ## match w/capture: one or more alpha posix characters ( [[:alpha:]]+ ) \z /;

the comments are a little verbose. i'd consider them extraneous for this example, but neccessary in more complex patterns.

~Particle *accelerates*


Comment on Re: "Correct" program style questions
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2014-10-22 23:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (122 votes), past polls