Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: Search replace with a block

by santoshrao99 (Initiate)
on May 12, 2016 at 02:20 UTC ( [id://1162826]=note: print w/replies, xml ) Need Help??


in reply to Re: Search replace with a block
in thread Search replace with a block

I understand the difference now. Thank you. Is it more simple if I slurp the entire thing in and match the start end and replace the value as compared to doing a tie::file ? Also I am sorry for the noobish question, but is there a way to get into the match's block and do the replace in a single regex.

Replies are listed 'Best First'.
Re^3: Search replace with a block
by hippo (Bishop) on May 12, 2016 at 09:50 UTC

    There are many, many different ways to approach this and identifying which is simplest is a very subjective measure. Try some of the approaches and see which you think appears simplest to you and just go with that one. TIMTOWTDI.

    You could construct a single regex to do a multiline match and replace but that will certainly be far from the simplest approach. I would recommend Apache::Admin::Config over such a complicated approach any day. Note that this is a pure-perl module so you can just use the source if necessary.

    However, here's the general all-in-one method:

    #!/usr/bin/env perl use strict; use warnings; my $in = <<EOT; <Location /> MaxConnPerIP 12 NoIPLimit image/* </Location> EOT my $max = 16; my $out = $in; $out =~ s/(<Location .+?MaxConnPerIP\s+)(?:\d+)(.+?<\/Location>)/$1$ma +x$2/s; print $out;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-04-24 03:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found