develooper Front page | perl.perl5.porters | Postings from June 2013

Re: [perl #117447] re modifier "h" - return named captures as hash expression

Thread Previous | Thread Next
From:
Tom Christiansen
Date:
June 29, 2013 19:37
Subject:
Re: [perl #117447] re modifier "h" - return named captures as hash expression
Message ID:
5687.1372534612@chthon
"James E Keenan via RT" <perlbug-followup@perl.org> wrote
   on Sat, 29 Jun 2013 07:12:06 PDT: 
> 
> Make the C<h> (mnemonic I<hash>) flag work (that line with the C<m>
> operator):
> 
>     my $fmt1 = '(?<y>\d\d\d\d)-(?<m>\d\d)-(?<d>\d\d)';
>     my $fmt2 = '(?<m>\d\d)/(?<d>\d\d)/(?<y>\d\d\d\d)';
>     my $fmt3 = '(?<d>\d\d)\.(?<m>\d\d)\.(?<y>\d\d\d\d)';
> 
>     for my $d (qw(2006-10-21 15.01.2007 10/31/2005)) {
>         if (my (%date) = $d =~ m{$fmt1|$fmt2|$fmt3}h) {
>             while (my ($k,$v) = each %date) {
>                 print "$k = $v\n";
>             }
>         }
>     }
> 
> Works the same as:
> 
>         if ($d =~ m{$fmt1|$fmt2|$fmt3}) {
>             my %date = %+;

I am opposed.  If it "works the same as", we don't need another way.

It increases the cognitive load unnecessarily for no real gain.

And I don’t want us to keep adding /mods.  We have to think of 
another way, something that embeds them and isn't stuck at mysterioius
one-letter identifiers.

--tom

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About