Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hello again.

I've got a script that uses named capture groups to parse file records. The record format is always the same (four fields wide, colon separated), just like a passwd file (except for the number of fields).

For example:

0:1:bob:Bob
1:1:bob:Bob
1:0:alice:Alice

You get the idea. At first I used to split it, but later I came to the conclusion that using a regex with named groups could provide a more understandable code. The (simplified) example below might help you get the picture.

if (/^(?<type>[01]):(?<valid>[01]):(?<name>[^:]+):(?<comment>[^:]+)$/) + { print "Key name: ", $+{name}, "\n"; print "Key Comment: ", $+{comment}, "\n"; print "Not valid\n" unless $+{valid} || !$+{type}; } else { print "Malformed input: $_\n"; }

Now, I've noticed (according to perlretut) that named capture groups were introduced in Perl 5.10. I don't expect the script to run in older versions, but would it be wise to use v5.10 pragma?

Would it have any unwanted side effects? I'm not using any of the features of the bundle, just wanted to state that version 5.10 is required. Is that a good idea?


In reply to Should I use v5.10 because of named groups? by hrcerq

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-19 13:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found