depends how far you want to go. Full example as follows...%hash = split /X/, 'fooXbar' # added the missing comma ;)
(BTW I did try to do this with Tie::StdHash, but couldn't figure it out)
#!/usr/bin/perl use strict; use Data::Dumper; tie my %hash, 'ExpandingHash'; $hash{'still'} = 'here'; %hash = split /X/, 'fooXbar'; print Dumper(\%hash); # I also added a new clear method, which you could use like this. # tied(%hash)->FORCE_CLEAR; __OUTPUT__ $VAR1 = { 'foo' => 'bar', 'still' => 'here' }; #================================================================== package ExpandingHash; use strict; sub TIEHASH { my %self; bless \%self, shift } sub FETCH { $_[0]->{$_[1]} } sub STORE { $_[0]->{$_[1]} = $_[2] } sub FIRSTKEY { each %{$_[0]} } sub NEXTKEY { each %{$_[0]} } sub CLEAR { } # NOT IMPLEMENTED sub DELETE { delete $_[0]->{$_[1]} } sub EXISTS { exists $_[0]->{$_[1]} } sub FORCE_CLEAR { %{$_[0]} = () }
In reply to Re^2: Assign (key, value) to a hash w/o clobbering hash
by reasonablekeith
in thread Assign (key, value) to a hash w/o clobbering hash
by Melly
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |