I noticed that too and not sure if it is relevant, but I have been stung by something similar in the past. I would re-write the subroutine as:
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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|