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 (Archbishop) 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;