hrcerq has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Should I use v5.10 because of named groups?
by Fletch (Bishop) on Apr 13, 2021 at 22:36 UTC | |
by hrcerq (Scribe) on Apr 14, 2021 at 16:16 UTC | |
by Marshall (Canon) on Apr 14, 2021 at 22:44 UTC | |
Re: Should I use v5.10 because of named groups?
by ikegami (Patriarch) on Apr 14, 2021 at 01:01 UTC | |
by hrcerq (Scribe) on Apr 14, 2021 at 16:18 UTC | |
Re: Should I use v5.10 because of named groups?
by choroba (Cardinal) on Apr 14, 2021 at 08:01 UTC | |
Re: Should I use v5.10 because of named groups?
by haj (Vicar) on Apr 14, 2021 at 10:05 UTC | |
Re: Should I use v5.10 because of named groups?
by perlfan (Vicar) on Apr 14, 2021 at 03:29 UTC | |
by hrcerq (Scribe) on Apr 15, 2021 at 19:28 UTC |