in reply to Confounded With A Simple Self-Made Perl Mod
$raw_dataPtr = \%{$element_stats_hash{$element_name}{'raw_data'}}; $$raw_dataPtr{$time} = {$var};
I think you want something like this:
#!/usr/bin/perl use Data::Dumper; my $time = time(); my $val = 0.12205589; my $element_name = "foo"; $element_stats_hash{$element_name}{'raw_data'}{$time} = $val; # <-- print Dumper $element_stats_hash{$element_name}; __END__ $VAR1 = { 'raw_data' => { '1229382894' => '0.12205589' } };
Update: That said, there's nothing wrong with using an intermediate variable, in particular if you should end up needing it multiple times:
# init raw data hash somewhere $element_stats_hash{$element_name}{'raw_data'} = {}; # then later my $raw_data = $element_stats_hash{$element_name}{'raw_data'}; $raw_data->{$time} = $val; $raw_data->{$another_time} = $another_val; #...
But note the difference with respect to autovivication... which is why we need to init an (empty) 'raw data' hash in this case, before we can take a ref to it.
Also, please use the arrow syntax for dereferencing — it's much more readable (and less ambiguous) than $$raw_data{$time} when the expressions get more complex...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Confounded With A Simple Self-Made Perl Mod
by o2bwise (Scribe) on Dec 16, 2008 at 20:09 UTC | |
by almut (Canon) on Dec 16, 2008 at 21:20 UTC |