I am trying to edit the cfg file inside inside a perl script, but it does not work if I read user input before that. Here is a test script to recreate the problem that I am seeing.
use strict;
my $TRACE_CFG = "trace.cfg";
print "Continue [y/N]> ";
my $continue = <>;
{
local $^I = '.bak';
local @ARGV = ($TRACE_CFG);
while (<>) {
s/search/replace/;
print;
}
unlink("$TRACE_CFG.bak");
}
Editing works if I comment on "my $ continue = <>;" line. If I read the user input, it looks like the @ARGV setting for the trace.cfg file does not take effect, and the while loop is waiting for input from STDIN. I can get around this using sed or using a temporary file and renaming it, but I would like to know the reason for this behavior and the correct way to do it.
source
share