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

[perl #51848] Deparse interpolation in regex literal

Thread Next
Zsban Ambrus
March 18, 2008 08:20
[perl #51848] Deparse interpolation in regex literal
Message ID:
# New Ticket Created by  Zsban Ambrus 
# Please include the string:  [perl #51848]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
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:

  -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"'
  -e syntax OK
  $ perl -MO=Deparse,-q -e '"${x}y"'
  $x . 'y';
  -e syntax OK
  $ perl -MO=Deparse -e '/${x}y/'
  -e syntax OK
  $ perl -MO=Deparse,-q -e '/${x}y/'
  -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/, $/'
  $ 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,


[Please do not change anything below this line]
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:
    osname=linux, osvers=, archname=i686-linux
    uname='linux king #3 smp tue may 29 09:42:52 cest 2007
i686 gnulinux '
    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
    cc='gcc', ccflags ='-fno-strict-aliasing -pipe
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    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',
    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/, so=so, useshrplib=false, libperl=libperl.a
  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:

Environment for perl 5.10.0:
    LANG (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About