Hi,
I'm trying to find a easy way to delete a line based on an ID number. My flat file is in the following format (example)
I'm using the following code to delete a specific line
But I don't want to store a backup in order to achieve this. Is there any other way to it ? Also, to update a line (only certain fields of the line) is there an easy way also ?
Thank you in advance for your help
I'm trying to find a easy way to delete a line based on an ID number. My flat file is in the following format (example)
Code:
test.txt
ID|Name|City|State
10|Bob|Carson|CA
12|Bobby|LongBeach|CA
I'm using the following code to delete a specific line
Code:
sub deleteUser {
my ($file, $dl_user) = @_;
local $^I = "";
local @ARGV = ($file);
while (<>) {
my ($user) = split /:/;
print unless $user eq $dl_user;
}
}
$file = "test.txt";
$user = "10";
&deleteUser($file,$user);
But I don't want to store a backup in order to achieve this. Is there any other way to it ? Also, to update a line (only certain fields of the line) is there an easy way also ?
Thank you in advance for your help