http://www.perlmonks.org?node_id=1019881

PilotinControl has asked for the wisdom of the Perl Monks concerning the following question:

my code below works fine updating the line in a file however it deletes all other records...not sure why? Thanks in advance for the solution to the code below.

sub editgenord { print colored ("| ORIGINAL DATE: |\n\n",'green'); my $origgenordDate = <STDIN>; chomp $origgenordDate; print colored ("| REVISED DATE: |\n\n",'green'); my $revgenordDate = <STDIN>; chomp $revgenordDate; my $file = "generalorderdata.txt"; local $^I = ".bak"; local @ARGV = ($file); while (<>) { chomp; my ($origDate,$gnOrd,$revDate) = split(/\:/); if ($origDate eq $origgenordDate) { print "$origDate:$gnOrd:$revgenordDate\n"; } } unlink("$file.bak"); close $file; print colored ("GENERAL ORDER UPDATED SUCCESSFULLY!!\n",'green'); sleep 3; genord(); } # END UPDATE GENERAL ORDER