scientologyboxing has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: attempting to achieve something
by choroba (Cardinal) on Mar 16, 2022 at 13:35 UTC
    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]
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: attempting to achieve something
by 1nickt (Canon) on Mar 16, 2022 at 13:35 UTC

    Not much of a communicator are we?

    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.
      > "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

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

Re: attempting to achieve something
by LanX (Saint) on Mar 16, 2022 at 13:30 UTC
    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

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery