in reply to Update Multiple Files

I populated three files with fake ids, populated the package vars and imported move from File::Copy. It changed all three files.
#!/usr/bin/perl use strict; use warnings; use File::Copy qw{ move }; sub update_lcrecord_now { my ($lcid,$lcroadname,$lcroadnumber,$locotype,$lcowner,$lcinterrr, +$lcassign) = @_; open my $lcinfile, '<',"$rrconfig::locodata" or die $!; open my $lcinfile2, '<',"$rrconfig::availlocodata" or die $!; open my $lcinfile3, '<',"$rrconfig::availlocoyng" or die $!; open my $lcoutfile, '>', "$rrconfig::locotemp" or die $!; open my $lcoutfile2, '>', "$rrconfig::availlocotemp" or die $!; open my $lcoutfile3, '>', "$rrconfig::availynglocotemp" or die $!; while (<$lcinfile>) { s/^$lcid\:.*/$lcid\:$lcroadname\:$lcroadnumber\:$locotype\:$lc +owner\:$lcinterrr\:$lcassign/g; print $lcoutfile $_; } while (<$lcinfile2>) { s/^$lcid\:.*/$lcid\:$lcroadname\:$lcroadnumber\:$locotype\:$lc +owner\:$lcinterrr\:$lcassign/g; print $lcoutfile2 $_; } while (<$lcinfile3>) { s/^$lcid\:.*/$lcid\:$lcroadname\:$lcroadnumber\:$locotype\:$lc +owner\:$lcinterrr\:$lcassign/g; print $lcoutfile3 $_; } close $lcoutfile; close $lcoutfile2; close $lcoutfile3; move "$rrconfig::locotemp", "$rrconfig::locodata" or die "move fai +led: $!"; move "$rrconfig::availlocotemp", "$rrconfig::availlocodata" or die + "move failed: $!"; move "$rrconfig::availynglocotemp", "$rrconfig::availlocoyng" or d +ie "move failed: $!"; } sub populate { open my $out, '>', shift or die $!; print {$out} "id0:xxx\n"; close $out; } populate($_) for 1 .. 3; $rrconfig::locodata = '1'; $rrconfig::availlocodata = '2'; $rrconfig::availlocoyng = '3'; $rrconfig::locotemp = '1.tmp'; $rrconfig::availlocotemp = '2.tmp'; $rrconfig::availynglocotemp = '3.tmp'; update_lcrecord_now(qw(id0 roadname0 road0 loco0 owner0 inter0 assign0 +));

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Update Multiple Files
by PilotinControl (Pilgrim) on Jan 05, 2021 at 15:19 UTC

    @Choroba: your code worked perfectly in stand alone mode. I think there might be an issue with my code since the 3rd file is in a completely different directory than the other 2 files are.

      And do you correctly set $rrconfig::availlocoyng to the full or relative path to the file? Is it just a different directory, or a completely different drive?

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

        @Choroba: here is the absolute path in the rrconfig.pm:

        $availlocoyng = "C:/DATA/YNGYRD/LOCOPOOL/availlocoyng.txt";

        The other 2 files are in the "C:/DATA"; directory.