John H. Robinson, IV wrote:
Andrew Lentvorski wrote:
Also, Perl needs to suck it up and put named groups in its regex engine.

What is the benefit of:

        (?P<id>[a-zA-Z_]\w*)              m.group('id')

over
        ([a-zA-Z_]\w*)                  $1
?

Why do so many Perl subroutines use named parameters rather than positional parameters?

Code maintenance.

Take a recursive descent parser, for instance. If I need to add another token in the middle or adjust the grammar rules, the tokens all rearrange which positional group they fall into.

It's simply an extension of the DRY (Don't Repeat Yourself) principle. With the named parameter, the match and the match name are encoded together once. With the Perl version, the match/match name mapping are encoded twice--once in the regex and once in whatever pulls apart the positional parameters.

-a


--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list

Reply via email to