If you have key => value pairs then a hash is the way to go:
my %hash; # get data as hash open FILE, $file or die $!\n; while (<FILE>) { my ($key, $value) = split; $hash{$key} = $value; } close FILE; my %changes = ( 'str1' => 'val1', 'str2' => 'val2' ); # change data in hash (or add new elements) $hash{$_} = $changes{$_} for keys %changes # overwrite old file with modified hash open FILE, ">$file" or die $!; print FILE "$_\t$hash{$_}\n" for keys %hash; close FILE;
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
In reply to Re: searching a file
by tachyon
in thread searching a file
by hotshot
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |