Re: Modify File in Place



On Apr 27, 1:34 pm, banker123 <bradbrock...@xxxxxxxxx> wrote:
local $^I = q{};
local @ARGV = ('E:/Remitrac/PDD/rmtd07110/Transmit/712531.dat');

while (<>) {
if(/^04/){
my $aux = (split/,/)[7];
$aux=~ s/^0+//;
print;

}
}

Can not do in place edit without backup error?

You did not mention you are on Windows. That's relevant. In that
case, you have to give $^I an actual value, say ".bkp", to create the
back up. Then you're free to remove that backup when the script ends.

Also I want this
script to edit the variable as defined above and leave all other
records in the file with the existing file name.

That's not what your original script did. Your original script was
only printing the $arg value, not anything else. Please take more
care to compose your posts, and you'll get better help.

{
local $^I = '.bkp';
local @ARGV = ( 'data.txt' );
while (<>) {
if (/^04/) {
my @vals = split / ,/;
$vals[7] =~ s/^0+//;
$_ = join(' ,', @vals);
}
}
continue {
print;
}
}



.



Relevant Pages

  • Re: Modify File in Place
    ... Can not do in place edit without backup error? ... This happens on Windows. ... Unmake the change you made to Paul's script and add an else clause ...
    (perl.beginners)
  • Re: Modify File in Place
    ... script to edit the variable as defined above and leave all other ... That's not what your original script did. ... unchanged data too. ... editing" works we wouldn't have had a question. ...
    (perl.beginners)