John W. Krahn wrote: > Steve Bertrand wrote: >> I'm still trying to figure out references... in the below diff, the '+' >> works ok as a passed-in hashref to an outside module, but the '-' does >> not. >> >> $plan_status is *absolutely* a hashref, as I have created it as such by >> hand (and verified it with Data::Dumper). >> >> When I pass $plan_status without surrounding it with braces, I receive a >> "not a HASH reference", but with the braces, the program continues >> normally. >> >> What significance do the braces have here? Am I doing something wrong? >> >> ISP % svn diff >> Index: lib/ISP/GUI/Accounting.pm >> =================================================================== >> --- lib/ISP/GUI/Accounting.pm (revision 505) >> +++ lib/ISP/GUI/Accounting.pm (working copy) >> @@ -116,7 +116,7 @@ >> my $plan_status_select = menu ( >> name => 'plan_status', >> values => $plan_status_key, >> - labels => $plan_status, >> + labels => {$plan_status}, >> ); >> >> $self->pb_param( plan_status => $plan_status_select ); > > The braces create an anonymous hash and return a reference to that hash. > If you had warnings enabled you would have received the warning: > > Odd number of elements in anonymous hash at lib/ISP/GUI/Accounting.pm > line 119. > > So I'm guessing that $plan_status is not a hash reference.
I do have warnings enabled. This is a CGI app, and I'm finding it very hard to troubleshoot even with this: use warnings; use strict; use CGI::HTMLError trace => 1; Perhaps I'm not creating a hashref properly, but there are other inconsistencies I've noticed as well with either the documentation for the module I'm using, or my code (I'm *much* more apt to blame the latter ;) The docs state: "values: This is an array-ref of values used for each of the option tags." "labels: This is a hash-ref of values to provide different values for the user-visible label of each option tag. Each key should match a value provided by the values parameter." Providing insight here as to what I'm doing wrong will really help me solidify many things Perl :) Here is my code, and following that what it claims to be when I 'retrieve' it using Storable: __CODE__ my $plan_status_key = $vardb->plan_status('key'); # arrref of keys my $plan_status = $vardb->plan_status(); # hashref my $plan_status_select = menu ( name => 'plan_status', values => $plan_status_key, labels => {$plan_status}, ); my @store = ($plan_status_key, $plan_status); # natively passed as refs store (\...@store, '/home/steve/error.txt'); __END__ % tests/retrieve.pl $VAR1 = \[ [ 'hold', 'active', 'flag', 'erase' ], \{ 'hold' => 'On Hold', 'active' => 'Active', 'erase' => 'Erase', 'flag' => 'Flag' } ]; Steve ps. after looking at it, it appears to me to be all wrong. It almost looks like I'm creating an arrayref of an array and a hashref...
smime.p7s
Description: S/MIME Cryptographic Signature