Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

m'...' interpolates escape sequences #6360

Closed
p5pRT opened this issue Mar 7, 2003 · 5 comments
Closed

m'...' interpolates escape sequences #6360

p5pRT opened this issue Mar 7, 2003 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 7, 2003

Migrated from rt.perl.org#21491 (status was 'resolved')

Searchable as RT21491$

@p5pRT
Copy link
Author

p5pRT commented Mar 7, 2003

From ksperling@web.de

Created by ksperling@web.de

In non-interpolating regex constructs like m'',
double-quote style backslash sequences like \n or
\x0A are nevertheless interpreted.

In interpolating regex constructs, when interpolating
a variable into the regex, double-quote backslash
sequences inside the variable are also interpolated (again).
This case can be rather confusing, because if the
variable was assigned from a double-quoted string, the
the DQ sequences are interpreted twice (see code snippet).

This doesn't seem to be the right behaviour, as \n, \r, \x
and so on aren't RE backslash sequences, but double-quote
backslash sequences. Perldoc perlop (gory details...) seems
to indicate that only RE backslash sequences like \b, \z, ...
should be interpreted at that stage, because DQ sequences have
already been handled by the quote-like parsing of the regex
constructor (in case of m//) or shouldn't be handled (in case
of m'').

If the current behaviour is indeed intended, the documentation
should be clarified.

Demonstration Code​:

#!perl -wl
# match literal <backslash> 'n'
$x = qr/\\n/;
$y = "\\n";
print(("\n" =~ /$x/) + 0);
print(("\n" =~ /$y/) + 0);
print(("\n" =~ $x) + 0);
print(("\n" =~ $y) + 0);

print("---");

$x = '\x50';
print 'P' =~ /$x/ + 0;
print 'P' =~ m'\x50';
__END__

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl v5.8.0:

Configured by ActiveState at Fri Nov  8 00:53:50 2002.

Summary of my perl5 (revision 5 version 8 subversion 0) configuration:
  Platform:
    osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    usethreads=undef use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cl', ccflags ='-nologo -Gf -W3 -MD -DNDEBUG -O1 -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT  -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX',
    optimize='-MD -DNDEBUG -O1',
    cppflags='-DWIN32'
    ccversion='', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -release  -libpath:"E:/Devel/Perl\lib\CORE"  -machine:x86'
    libpth="E:\Devel\Perl\lib\CORE"
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib msvcrt.lib
    perllibs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib
    gnulibc_version='undef'
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release  -libpath:"E:/Devel/Perl\lib\CORE"  -machine:x86'

Locally applied patches:
    ACTIVEPERL_LOCAL_PATCHES_ENTRY


@INC for perl v5.8.0:
    E:/Devel/Perl/lib
    E:/Devel/Perl/site/lib
    .


Environment for perl v5.8.0:
    HOME=F:\Data
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;E:\Tools\Cmd;E:\Applications\Miktex\Miktex\bin;E:\Devel\Tools;E:\Devel\Perl\Bin;E:\Devel\JDK\bin
    PERL_BADLANG (unset)
    SHELL (unset)


@p5pRT
Copy link
Author

p5pRT commented Jul 5, 2005

From @schwern

[ksperling@​web.de - Thu Mar 06 17​:17​:50 2003]​:

In non-interpolating regex constructs like m'',
double-quote style backslash sequences like \n or
\x0A are nevertheless interpreted.

I call this a bug. The docs state that m'' does not interpolate and
that "escape sequences are available in constructs that interpolate and
in transliterations".

@p5pRT
Copy link
Author

p5pRT commented Jul 5, 2005

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Nov 2, 2016

From @demerphq

I am closing this ticket.

The behavior is as expected and the documentation has been updated accordingly.

m'\n' does not refer to the *character* "\n", and is not interpolated, it is a regex meta-pattern (like \s) that happens to only match the character "\n".

In fact ALL escapes are regex meta-patterns, and therefor the only thing that can be interpolated is vars, which are not interpolated in m''.

The documentation has been updated to say "no variable intepolation" to make this clear.

@p5pRT
Copy link
Author

p5pRT commented Nov 2, 2016

@demerphq - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant