From 25901373d46b88a1b60374431b887cd07f527c65 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 2 Jul 2009 11:38:49 +0200 Subject: Simplestore.pm: Fixed overwriting for existing keys --- lib/Simplestore.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/Simplestore.pm') diff --git a/lib/Simplestore.pm b/lib/Simplestore.pm index 4e878b4..222aab1 100644 --- a/lib/Simplestore.pm +++ b/lib/Simplestore.pm @@ -13,17 +13,18 @@ $VERSION = '1.0'; sub load { my $file = shift; - my ($store, $key, $value); + my ($store, $key, $value, @keys); $store = shift if @_; open(my $handle, '<', $file) or confess("Cannot read $file: $!"); while (<$handle>) { chomp; /^(\S+)\s+(.*)$/ or next; ($key, $value) = ($1, $2); - if (exists($store->{$key})) { + if (exists($store->{$key}) and grep {$_ eq $key} @keys) { $store->{$key} .= "\n$value"; } else { $store->{$key} = $value; + push(@keys, $key); } } close($handle); -- cgit v1.2.3