http://qs321.pair.com?node_id=11131280


in reply to Re: Should I use v5.10 because of named groups?
in thread Should I use v5.10 because of named groups?

I guess you're right, that regex isn't any more readable than the alternatives you propose. In fact, I've rewritten it to:

if (/^([01]):([01]):([^:]+):([^:]+)$/) { my ($type, $valid, $name, $coment) = ($1, $2, $3, $4); ...
I maintained the regex as I'm fairly sure I'll need to improve it later for more checks on the input.

Replies are listed 'Best First'.
Re^3: Should I use v5.10 because of named groups?
by Marshall (Canon) on Apr 14, 2021 at 22:44 UTC
    Just a nit, in case you didn't know, but you can do the $1,$2,$3,$4 assignment in the if statement:
    if ( my ($type, $valid, $name, $coment) = $_ =~ m/^([01]):([01]):([^:]+):([^:]+)$/ ){}
    I don't think this makes much difference. I just have a coding preference to avoid $1, etc.
    I made 2 source lines because of code line length limits here. In actual code, I'd probably just have one line.