in reply to How to modify/delete records in a flat-file database?
There are more efficient ways, of course, but this will get the job done.my @names; my %nums; my %stats; my %oses; my $i=0; my $csv="data.csv"; # read data from $csv open CSV, $csv or die; flock(CSV, 1); while (<CSV>) { chomp; ($name,$num,$stat,$os) = split(':'); $nums{$name} = $num; $stats{$name} = $stat; $oses{$name} = $os; $names[$i] = $name; $i++; } close CSV; #make necessary changes to %nums, %stats, %oses as required, or delete + an entry entirely # write data over $csv open (CSV, '>', $csv) or die; flock(CSV, 2); foreach my $name(@names) { print CSV join(':',$name,$nums{$name},$stats{$name},$oses{$name}). +"\n"; } close CSV;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How to modify/delete records in a flat-file database?
by pelagic (Priest) on Apr 28, 2004 at 12:40 UTC | |
by TwistedGreen (Sexton) on Apr 28, 2004 at 12:45 UTC | |
by JoeJaz (Monk) on Apr 28, 2004 at 17:13 UTC |