Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: String replace, another question

by TomDLux (Vicar)
on Aug 26, 2011 at 14:53 UTC ( #922664=note: print w/replies, xml ) Need Help??

in reply to String replace, another question

I don't understand the question, I'm blinded by the long lines and can' find the problems.

You can use just about any characters as delimiters in s///, you don't have to use the slash. By using something else, say matching curly braxes, you don't have to excape all those slashes that are part of the text. And you don't have to searcxh character by character to find the separation between 'search' and 'replace'.

As well, if you want to specify 5 spaces, you can use \s{5} rather than \s\s\s\s\s. It means you don't have to count; you KNOW the pattern is looking for 5 of them. Ooops, there's actually 6 of them....proves my point. It doesn't matter that braces are nested, cause braces are balanced.

# Up in the Constants section # Readonly my $NL = "\n"; Readonly my $RETURN = "\r"; Readonly my $SPACE = q{ }; Readonly my $TAB = "\t" my $search_text = qr{<binddn>cn=abcde</binddn> # buttondown $NL # newline $SPACE{6} # 6 spaces <bindpass> # something .* # anything </bindpass> # end something }xms; my $replace_text = "<binddn>cn=abcde</binddn>$RETURN$TAB<bindpass>welc +ome1</bindpass>"; $line =~ s{$search_text} {$replace_text};

As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://922664]
[MidLifeXis]: And under MINGW64_NT-6.1 MYHOST 2.6.0(0.304/5/3) 2016-09-09 09:46 x86_64 Msys there seem to be issues with escapes in external build tool calls.
[Corion]: I mean, it's a technical feat it achieves, but... why? ;)
[MidLifeXis]: And it also has the 0.14 version of the tarball in its manifest.
[LanX]: avoiding unreadable brackets
[MidLifeXis]: Although the previous one could be a b0rken PATH, I would need to dig for that.
[thezip]: I've got to go to meetings now. If anyone has further comments regarding Spreadsheet::XLSX deployment to Strawberry Perl 5.24.1, please /msg me -- thanks!
LanX has to go ... plans to crash with a car into a group of pythonistas while screaming "LARRY IS THE GREATEST"
LanX ... darn ... where is my car?

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2017-03-23 17:30 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (291 votes). Check out past polls.