I have read the documentation and I might be running slow today, but for some reason I can't figure out how to implement it.
I have a flat file where I need to modify records with in the file that are passed by a user. There can be a single or multiple records to modify/delete.
In case of above the file is overwritten with no data.
Alternatively.
moving forward, do I need to split the @array and then compare each to record and then modify/delete? I've tried several things, but it seems to give the same end result of a file being overwritten or empty. With @array, I'm also worried about memory consumption.
Any advice...as it seems my brain has already taken to the festivities and refuses to think straight.
I have a flat file where I need to modify records with in the file that are passed by a user. There can be a single or multiple records to modify/delete.
Code:
use CGI qw/:all/;
use CGI::Carp qw(fatalsToBrowser);
use Date::Calc qw( Delta_Days Add_Delta_Days );
print "Content-type:text/html\n\n";
@p = (param());
@recordsToDelete = param($p[0]);
open file,"+> /path/to/file" || die "Cannot open file:($!)\
n";
foreach $recordToDelete (sort @recordsToDelete) {
($recordNumberToDel) = split (/\s+/,$recordToDelete);
while (<file>) {
($recordNumber,$many,$more) = split(/\|/,$_);
chomp ($recordNumber,$recordNumberToDel);
s/$recordNumber/Delete/g if ($recordNumber == $recordNumberToDel);
}
}
close file;
In case of above the file is overwritten with no data.
Alternatively.
Code:
use Tie::File;
tie @array,Tie::File,/path/to/file or die ($!\n);
foreach $recordToDelete (sort @recordsToDelete) {
($recordNumberToDel) = split (/\s+/,$recordToDelete);
moving forward, do I need to split the @array and then compare each to record and then modify/delete? I've tried several things, but it seems to give the same end result of a file being overwritten or empty. With @array, I'm also worried about memory consumption.
Any advice...as it seems my brain has already taken to the festivities and refuses to think straight.