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

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

Thread Previous | Thread Next
From:
James E Keenan via RT
Date:
June 29, 2013 14:12
Subject:
[perl #117447] re modifier "h" - return named captures as hash expression
Message ID:
rt-3.6.HEAD-2552-1372515125-1849.117447-15-0@perl.org
On Tue Apr 02 07:36:23 2013, daxim wrote:
> 
> This is a bug report for perl from daxim@cpan.org,
> generated with the help of perlbug 1.39 running under perl 5.16.3.
> 
> 
> -----------------------------------------------------------------
> [Please describe your issue here]
> 
> Example code adapted from perlretut.
> 
> 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 = %+;
> 
> Rationale: side effects are a weird-ass way to program in a language
> that actually has operators/expressions/functions which are able to
> return values. I'd like eventually to get rid of side effects, but
> first there actually must be a way to do something without involving
> action at a distance. If you can't see what's wrong with the code just
> above, imagine you had do this to get the length of something:
> 
>     length($something);
>     # according to perlvar, $ˑ is set to the last successful length
>     # measuring
>     print "something is $ˑ long";
>     # take care not to use an outdated $ˑ or accidently overwrite
>     # it!   :-o
> 

This RT is a request for a new feature:  a new regex modifier '/h'.

Is there any support for development of this new feature?  (I ask, in
part, because it hasn't received a "second the motion" in the three
months since the request was originally filed.)

Is there anyone who wants to try to write an implementation for this new
feature?

Thank you very much.
Jim Keenan


---
via perlbug:  queue: perl5 status: new
https://rt.perl.org:443/rt3/Ticket/Display.html?id=117447

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