in reply to Re^3: Search replace with a block
in thread Search replace with a block
Now the issue I have is $block has the updated text and $file has the entire file. How do I merge those , by merge meaning either remove the matching block and add this new one. Or change my value into the original variable which has the file. Which is part of the reason I was leaning on using tie::file, updating the file was so much more easier. Let me know what you guys think. Thank you for your help.#!/usr/bin/perl -w use strict; my $location ="/newlocation"; my $file_name ='ipconn.conf'; $/ = undef; open (FILE, "< $file_name") or die $!; my $file = <FILE>; close FILE; my $value; # check for the block we want if ($file =~ m/\<Location\ $location.+?\<\/Location\>/s){ my $block = $&; if($block =~ s/MaxConnPerIP\s*(.+?)*/MaxConnPerIP 10/g) { print $block; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Search replace with a block
by beech (Parson) on May 12, 2016 at 06:31 UTC | |
by santoshrao99 (Initiate) on May 12, 2016 at 08:04 UTC |