If I understand you correctly, you want us to write code calling the function that would compile. The following not only compiles, but also runs without problems (in 5.26.1):
#!/usr/bin/perl
use warnings;
use strict;
sub mixedregex {
s[\\0([0-7]{3})][chr oct $1]egr;
}
$_ = '\0123';
print mixedregex(); # S
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
| [reply] [d/l] [select] |
use strict;
use warnings;
use feature 'say';
sub mixedregex {
my $foo = shift;
say length $foo;
$foo =~ s{\0([0-7]{3})}{chr oct $1}eg;
say length $foo;
return $foo;
}
say mixedregex("bar"."\0"."123");
__END__
$ perl 11142131.pl
7
4
barS
Hope this helps!
The way forward always starts with a minimal test.
| [reply] [d/l] [select] |
> "bar"."\0"."123"
when using doublequotes or interpolated regexes one needs to escape a leading backslash, hence "\\0"
your code is not replacing the string '\0' but the chr(0)
DB<13> x "\0"
0 "\c@"
DB<14> x chr(0)
0 "\c@"
DB<15> x '\0' # with singlequotes escaping is only needed for \ and
+'
0 '\\0'
DB<16> p '\0' eq '\\0'
1
| [reply] [d/l] [select] |
I have no clue what your question is, and I don't wanna guess.
(something about breeding JS-monkeys with skirts?)
Maybe try providing a SSCCE, if wording and punctuation are too complicated?
update
after staring at the screen it seems like that Perl regex is translating octal code \0123 into characters and you want help translating it to JS?
I'd say have a look at the String and the RegExp objects, there you'll find .replace or .replace_all methods working like a Perl regex with /g modifier. JS copied almost all regex features available in Perl4.
update
yep off topic, but here you go
replaceAll
Hint: you'll need a replacer function for /e
update
see also
replace#using_global_and_ignore_with_replace
| [reply] [d/l] [select] |