my $type = event_hasher(\@event); sub event_hasher { my $cur_event = shift; my %event_hash; for my $item (@$cur_event) { $item =~ s/://g; my ($key,$value) = split / /, $item; $event_hash{$key} = $value; } return \%event_hash; } $queue_changes{$event_id} = $type;
Update:
As choroba points out below this doesn't solve the problem - in fact it creates it! You need to make a copy of the input - but you are doing that anyway so the aliasing is not the problem. Using choroba's test with your subroutine:
sub event_hasher { my @cur_event = @{$_[0]}; my %event_hash; foreach(@cur_event){ $_ =~ s/://g; my @place_holder = split / /, $_; $event_hash{$place_holder[0]} = $place_holder[1]; } return %event_hash; } my @event = ('a:b c:d'); print "@event\n"; my %type = event_hasher(\@event); print "@event\n"; # prints: a:b c:d a:b c:d
In reply to Re^2: Ending up with duplicate keys in a hash?
by tangent
in thread Ending up with duplicate keys in a hash?\
by coffeemaster1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |