# New Ticket Created by Joseph Polanik # Please include the string: [perl #127352] # in the subject line of all future correspondence about this issue. # <URL: https://rt.perl.org/Ticket/Display.html?id=127352 >
Constants are not required to have a sigil but apparently they may. Unfortunately, when a constant with a sigil contains a regex pattern, unpredictable results may occur. The attached file show that a regex pattern that should detect the file system separator ('/' or '\') yield incorrect results when contained in a constant whose names contains a sigil but correct results otherwise. Identical results were obtained on Linux (Ubuntu 12.04) and Mac OS X 10.10.5 Build information Linux $ perl6 -version This is Rakudo version 2015.12 built on MoarVM version 2015.12 implementing Perl 6.c. Mac $ perl6 -version This is Rakudo version 2015.12-176-gaefe2c2 built on MoarVM version 2015.12-29-g8079ca5 implementing Perl 6.c. Thanks, Joseph Polanik
#!/usr/bin/env perl6 # Constants are not required to have a sigil. When they have a sigil and # contain a regex, the results are unpredictable. constant $sepreg = /(<[\\\/]>)/; my $sepreg2 = /(<[\\\/]>)/; constant sepreg3 = /(<[\\\/]>)/; my $filenameW = "c:\\g\\b.mp4"; my $filenameL = "/g/b.mp4"; say "============= Looking for a Windows separator: \\"; # The match is made but $/ doesn't get populated say "Testing regex as a constant with a sigil: Windows separator"; if ($filenameW ~~ $sepreg) { say $/[0].Str; } else { say "No match for SEP"; } # Gives correct result say "Testing regex as a constant with no sigil: Windows separator"; if ($filenameW ~~ sepreg3) { say $/[0].Str; } else { say "No match for SEP"; } # Gives correct result say "Testing regex as a lexical variable: Windows separator"; if ($filenameW ~~ $sepreg2) { say $/[0].Str; } else { say "No match for SEP"; } # Gives correct result say "Testing regex as a string: Windows separator"; if ($filenameW ~~ /(<[\\\/]>)/) { say $/[0].Str; } # # Now try the same tests with a *nix file system # say "============= Looking for a *nix separator: /"; # The match is made but $/ doesn't get populated say "Testing regex as a constant with a sigil: *nix separator: Wrong Result"; if ($filenameL ~~ $sepreg) { say $/[0].Str; } else { say "No match for SEP"; } # Gives correct result say "Testing regex as a constant with no sigil: *nix separator"; if ($filenameL ~~ sepreg3) { say $/[0].Str; } else { say "No match for SEP"; } # Gives correct result say "Testing regex as a lexical variable: *nix separator"; if ($filenameL ~~ $sepreg2) { say $/[0].Str; } else { say "No match for SEP"; } # Gives correct result say "Testing regex as a string: *nix separator"; if ($filenameL ~~ /(<[\\\/]>)/) { say $/[0].Str; }