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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Update works for line...deletes other records
by Anonymous Monk on Feb 21, 2013 at 04:53 UTC | |
|
Re: Update works for line...deletes other records
by tmharish (Friar) on Feb 21, 2013 at 06:16 UTC | |
|
Re: Update works for line...deletes other records
by 7stud (Deacon) on Feb 21, 2013 at 07:52 UTC |