spstansbury has asked for the wisdom of the Perl Monks concerning the following question:

I need to run a script and output some data to be used at a later time. Subsequent running of the script will use the stored data as baseline values to compare against new data.

I'm using Storable:

push @{$baseline}, \%base_record; store( \$baseline, $baseline_records ) or die "Can't store %a in $base +line_records!\n";
%base_record has a number of key/value pairs and gets pushed onto @{$baseline} every iteration of the loop. After the loop finishes, I store the AoH's. $baseline_records refers to the data file.

Data::Dumper shows:

$VAR1 = { 'LICount' => 0, 'LICountBase' => 0, 'LIFloat' => 0, 'LIFloatBase' => 0, 'LIICount' => 0, 'LIICountBase' => 0, 'ProjectID' => 'STO1019001', }; $VAR2 = { 'LICount' => 0, 'LICountBase' => 0, 'LIFloat' => 0, 'LIFloatBase' => 0, 'LIICount' => 0, 'LIICountBase' => 0, 'ProjectID' => 'STO1018001', }; $VAR3 = { 'LICount' => 38, 'LICountBase' => 38, 'LIFloat' => 0, 'LIFloatBase' => 0, 'LIICount' => 11, 'LIICountBase' => 11, 'ProjectID' => 'STO1005001', };

When I retrieve the data, I'm getting:

my $arrayref = retrieve( $baseline_records ); print Dumper $arrayref; $VAR1 = \[ { 'LICount' => 0, 'LICountBase' => 0, 'LIFloat' => 0, 'LIFloatBase' => 0, 'LIICount' => 0, 'LIICountBase' => 0, 'ProjectID' => 'STO1019001', }, { 'LICount' => 0, 'LICountBase' => 0, 'LIFloat' => 0, 'LIFloatBase' => 0, 'LIICount' => 0, 'LIICountBase' => 0, 'ProjectID' => 'STO1018001', }, { 'LICount' => 38, 'LICountBase' => 38, 'LIFloat' => 0, 'LIFloatBase' => 0, 'LIICount' => 11, 'LIICountBase' => 11, 'ProjectID' => 'STO1005001', } ];

I know that I'm not dealing with the references properly. The goal is, upon subsequent running of the script, when I loop through the project to return the values based on matching a "ProjectID"

Thanks in advance for any pointers.

Scott...

Replies are listed 'Best First'.
Re: Storable, reference help needed
by afresh1 (Hermit) on Sep 27, 2010 at 22:28 UTC

    Is there a reason you are storing a reference to a reference of an array?

    Where you have store( \$baseline, $baseline_records ), maybe instead it should be store( $baseline, $baseline_records )?

    This gives me identical output:

    use Storable; use Data::Dumper; my $baseline_records = 'file.stor'; my $baseline = [ { 'LICount' => 0, 'LICountBase' => 0, 'LIFloat' => 0, 'LIFloatBase' => 0, 'LIICount' => 0, 'LIICountBase' => 0, 'ProjectID' => 'STO1019001', }, { 'LICount' => 0, 'LICountBase' => 0, 'LIFloat' => 0, 'LIFloatBase' => 0, 'LIICount' => 0, 'LIICountBase' => 0, 'ProjectID' => 'STO1018001', }, { 'LICount' => 38, 'LICountBase' => 38, 'LIFloat' => 0, 'LIFloatBase' => 0, 'LIICount' => 11, 'LIICountBase' => 11, 'ProjectID' => 'STO1005001', } ]; store( $baseline, $baseline_records ); my $arrayref = retrieve($baseline_records); print Dumper $baseline, $arrayref;

    l8rZ,
    --
    andrew
      Thank you!