This does not affect the real
%hash. By de-referencing it like that, you're essentially creating a copy. The item on the right-hand-side is now a real hash (by virtue of wrapping it in
%{...}), not a reference. Thus, you are effectively doing this:
%hash1 = %hash2;
This does not create an
alias, but a
copy. Changes to
%hash1 have no effect on
%hash2.
And no, you don't have to put parens around your split call. Perl does the correct thing here, but it may be more readable to others if you write it with parens anyway. Here is some test-case code you can try yourself:
sub test {
my $hash1 = shift;
my %hash2 = %{shift};
$hash1->{three} = 3;
$hash2{three} = 3;
}
my %a = (one => 1, two => 2);
my %b = (one => 1, two => 2);
&test(\%a, \%b);
print join(", ", keys %a), "\n";
print join(", ", keys %b), "\n";
# three, two, one
# two, one
-
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.