in reply to Re^2: using command line switches to edit file
in thread using command line switches to edit file

@line=<INFO>; #will this help ?
Not at all. That construct will read the whole file into an array lines. That's not what you want here. Have a look at this code.
my $file = $ARGV[0]; my $repl = $ARGV[1]; open INFO, "<", $file or die $!; while (<INFO>) { s/(Absolute_Error_Tolerance=&Quot;)1e-15(&Quot)/$1$repl$2/; print; } close INFO;
That can be easily made into a one-liner:
perl -n -e "s/(Absolute_Error_Tolerance=&Quot;)1e-15(&Quot)/$1$ARGV[0] +$2/; print;" filename
just this doesn't work. You cannot pass additional variables into an -e "code" statement. However, you avoid problem by putting that line into a shell script or batchfile (here windows batchfile, as i have no idea of shell scripts).
@echo off perl -n -e "s/(Absolute_Error_Tolerance=&Quot;)1e-15(&Quot)/$1%2$2/; p +rint;" %1
So you can then call that file using
batchfilename datafile replacement
Note: The %1 and %2 are no perl hashes but variables from the shell. They get substituted by the command line values before! the script is run.


holli, /regexed monk/

Replies are listed 'Best First'.
Re^4: using command line switches to edit file
by kitty (Novice) on Feb 13, 2006 at 16:53 UTC
    Thankyou :) ..