develooper Front page | perl.perl5.porters | Postings from March 2008

[perl #51848] Deparse interpolation in regex literal

Thread Next
From:
Zsban Ambrus
Date:
March 18, 2008 08:20
Subject:
[perl #51848] Deparse interpolation in regex literal
Message ID:
rt-3.6.HEAD-25460-1205853136-882.51848-75-0@perl.org
# New Ticket Created by  Zsban Ambrus 
# Please include the string:  [perl #51848]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=51848 >


This is a bug report for perl from ambrus@math.bme.hu,
generated with the help of perlbug 1.36 running under perl 5.10.0.


-----------------------------------------------------------------
[Please enter your report here]

The following deparse command

  perl -MO=Deparse -e '/${x}y/'

gives a wrong output:

  /$xy/;
  -e syntax OK

This is wrong, because the original script interpolates the variable $x to
the regex, whereas the deparse output interpolates the variable $xy.
Compare the following:

  $ perl -MO=Deparse -e '"${x}y"'
  "${x}y";
  -e syntax OK
  $ perl -MO=Deparse,-q -e '"${x}y"'
  $x . 'y';
  -e syntax OK
  $ perl -MO=Deparse -e '/${x}y/'
  /$xy/;
  -e syntax OK
  $ perl -MO=Deparse,-q -e '/${x}y/'
  /$xy/;
  -e syntax OK

I believe the results for regex literals should be analogous to the string
literals: an interpolated variable name should be braced if the expression
would be ambiguous otherwise.  I'm not sure what the -q option should do in
the regex case.

To prove that the regex literal /${x}y/ is parsed right, so this is a
deparse bug, not a parser bug, either examine the Concise output, or
try this:

  $ perl -e '$x = "m"; print qr/${x}y/, $/'
  (?-xism:my)
  $ perl -MO=Deparse -e '$x = "m"; print qr/${x}y/, $/'
  $x = 'm';
  print qr/$xy/, $/;
  -e syntax OK

By the way, this seems to happen in perl 5.10.0, but not in 5.8.8.

Thanks in advance,

Ambrus


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

Configured by ambrus at Tue Dec 18 19:35:54 CET 2007.

Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.6.20.6, archname=i686-linux
    uname='linux king 2.6.20.6 #3 smp tue may 29 09:42:52 cest 2007
i686 gnulinux '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-fno-strict-aliasing -pipe
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-fno-strict-aliasing -pipe -I/usr/local/include'
    ccversion='', gccversion='4.1.1', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /usr/lib64
    libs=-lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.3.6.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.3.6'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib'

Locally applied patches:


---
@INC for perl 5.10.0:
    /usr/local/lib/perl5/5.10.0/i686-linux
    /usr/local/lib/perl5/5.10.0
    /usr/local/lib/perl5/site_perl/5.10.0/i686-linux
    /usr/local/lib/perl5/site_perl/5.10.0
    /usr/local/lib/perl5/site_perl/5.8.8
    /usr/local/lib/perl5/site_perl
    .

---
Environment for perl 5.10.0:
    HOME=/home/ambrus
    LANG (unset)
    LANGUAGE=en_HU:en_US:en_GB:en
    LC_CTYPE=hu_HU
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/ambrus/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
    PERL_BADLANG (unset)
    SHELL=/bin/bash


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