Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: attempting to achieve something

by 1nickt (Canon)
on Mar 16, 2022 at 13:35 UTC ( [id://11142134]=note: print w/replies, xml ) Need Help??


in reply to attempting to achieve something

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.

Replies are listed 'Best First'.
Re^2: attempting to achieve something (escaping rules)
by LanX (Saint) on Mar 16, 2022 at 15:06 UTC
    > "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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11142134]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-25 07:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found