Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Aliasing one hash to another

by imp (Priest)
on Jan 30, 2007 at 22:56 UTC ( #597462=note: print w/replies, xml ) Need Help??

in reply to Aliasing one hash to another

You should just fix the offending code. Modifying a global hash is a bad practice. If for some reason this is not possible then you can use a glob to alias the second hash temporarily.. but this is bad mojo and should be avoided.
use strict; use warnings; use Data::Dumper; use vars qw( %hash1 %hash2 ); %hash1 = (a => 1); %hash2 = (b => 2); do_badness(); print "hash1: ", Dumper \%hash1; print "hash2: ", Dumper \%hash2; sub do_badness { local *hash1 = \%hash2; bad_sub(); } sub bad_sub { $hash1{c} = 3; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://597462]
[stevieb]: I just received full professional license for ALL of JetBrains software due to requesting their opensource request form! I wanted only CLion, but they give them all
[stevieb]: I stated I use IDEA for Perl work, and at work, licensed version of PyCharm
[beech]: is that a good thing?

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2017-02-20 20:13 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (302 votes). Check out past polls.