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

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

Thread Previous | Thread Next
From:
Lars Dɪᴇᴄᴋᴏᴡ 迪拉斯
Date:
April 2, 2013 14:36
Subject:
[perl #117447] re modifier "h" - return named captures as hash expression
Message ID:
rt-3.6.HEAD-28177-1364913383-922.117447-75-0@perl.org
# New Ticket Created by  Lars Dɪᴇᴄᴋᴏᴡ 迪拉斯 
# Please include the string:  [perl #117447]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=117447 >



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

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=low
---
Site configuration information for perl 5.16.3:

Configured by daxim at Fri Mar 29 15:53:58 CET 2013.

Summary of my perl5 (revision 5 version 16 subversion 3) configuration:
   
  Platform:
    osname=linux, osvers=3.4.28-2.20-desktop,
archname=x86_64-linux-thread-multi-ld uname='linux champion
3.4.28-2.20-desktop #1 smp preempt tue jan 29 16:51:37 utc 2013
(143156b) x86_64 x86_64 x86_64 gnulinux ' config_args='-de
-Dprefix=/home/daxim/local/share/perlbrew/perls/perl-5.16.3 -DDEBUGGING
-Dusemorebits -Dusethreads -Dcf_email=daxim@cpan.org
-Dperladmin=daxim@cpan.org -Accflags=-fPIC
-Aeval:scriptdir=/home/daxim/local/share/perlbrew/perls/perl-5.16.3/bin'
hint=recommended, useposix=true, d_sigaction=define useithreads=define,
usemultiplicity=define useperlio=define, d_sfio=undef,
uselargefiles=define, usesocks=undef use64bitint=define,
use64bitall=define, uselongdouble=define usemymalloc=n,
bincompat5005=undef Compiler: cc='cc', ccflags ='-D_REENTRANT
-D_GNU_SOURCE -fPIC -DDEBUGGING -fno-strict-aliasing -pipe
-fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64', optimize='-O2 -g', cppflags='-D_REENTRANT
-D_GNU_SOURCE -fPIC -DDEBUGGING -fno-strict-aliasing -pipe
-fstack-protector -I/usr/local/include' ccversion='', gccversion='4.7.2
20130108 [gcc-4_7-branch revision 195012]', gccosandvers='' intsize=4,
longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=8, nvtype='long double', nvsize=16,
Off_t='off_t', lseeksize=8 alignbytes=16, prototype=define Linker and
Libraries: ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
libpth=/usr/local/lib /lib/../lib64 /usr/lib/../lib64 /lib /usr/lib /lib64 /usr/lib64 /usr/local/lib64
libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
-lgdbm_compat perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
libc=/lib/libc-2.17.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.17' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so,
d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fPIC',
lddlflags='-shared -O2 -g -L/usr/local/lib -fstack-protector'

Locally applied patches:
    

---
@INC for perl 5.16.3:
    /home/daxim/local/share/perlbrew/perls/perl-5.16.3/lib/site_perl/5.16.3/x86_64-linux-thread-multi-ld
    /home/daxim/local/share/perlbrew/perls/perl-5.16.3/lib/site_perl/5.16.3
    /home/daxim/local/share/perlbrew/perls/perl-5.16.3/lib/5.16.3/x86_64-linux-thread-multi-ld
    /home/daxim/local/share/perlbrew/perls/perl-5.16.3/lib/5.16.3
    .

---
Environment for perl 5.16.3:
    HOME=/home/daxim
    LANG=de_DE.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/cuda/lib:/usr/lib64/mpi/gcc/openmpi/lib64
    LOGDIR (unset)
    PATH=/home/daxim/local/share/perlbrew/bin:/home/daxim/local/share/perlbrew/perls/perl-5.16.3/bin:/home/daxim/local/bin:/usr/local/cuda/bin:/opt/kde3/sbin:/sbin:/usr/sbin:/usr/lib64/mpi/gcc/openmpi/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/usr/lib/mit/bin:/usr/lib/mit/sbin
    PERLBREW_BASHRC_VERSION=0.61
    PERLBREW_HOME=/home/daxim/.perlbrew
    PERLBREW_MANPATH=/home/daxim/local/share/perlbrew/perls/perl-5.16.3/man
    PERLBREW_PATH=/home/daxim/local/share/perlbrew/bin:/home/daxim/local/share/perlbrew/perls/perl-5.16.3/bin
    PERLBREW_PERL=perl-5.16.3
    PERLBREW_ROOT=/home/daxim/local/share/perlbrew
    PERLBREW_VERSION=0.61
    PERL_BADLANG (unset)
    SHELL=/bin/bash

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