Gossamer Forum
Home : General : Perl Programming :

Can't use an undefined value as a HASH reference

Quote Reply
Can't use an undefined value as a HASH reference
hi andy,
you helped me with the 'scalar' error when i was trying to show user list in select box on form. after playing with script more, i find it unfriendly that when i click Admin link in menu, it automatically brings up MY info from user table. i would prefer that the name, password, permissions etc be empty when i load the admin form. i want to either select a user from the list to edit an existing user OR type a new username and fill in the blanks to add a new user. when i'm ready to turn this database over to someone, i'm afraid they will constantly give admin permissions to new users, overwrite their own info, etc.

i believe the red line below is what loads my info. if i comment it out, i get the error in the subject of this post. don't know what to do!!!

Code:
sub admin_form {
#---------------------------------------------------------------------
# show admin form
#
my ($self, $user, $msg) = @_;

return $self->home($self->_language('PER_ADMIN')) unless ( $self->{user}->{admin_p} );
$user = admin_init_hash($self->{user}) if ( !$user );
return ('admin_form.html', {
header => $self->_language('HEA_ADMIN'), %$user,
db => $self->{cgi}->{db},
password_confirm => $self->{cgi}->{password_confirm},
msg => $msg
});
}
Quote Reply
Re: [delicia] Can't use an undefined value as a HASH reference In reply to
Try doing:

Code:
$user = {}; # set as a hash, but with no values

..instead of:

Code:
$user = admin_init_hash($self->{user}) if ( !$user );

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Can't use an undefined value as a HASH reference In reply to
this seems to work:

$user = {} if ( !$user );

when i left off the if statement, it failed to show info for the selected user! thank you! (and let me know if you think i've messed something up.)

Last edited by:

delicia: Aug 14, 2010, 1:39 PM
Quote Reply
Re: [delicia] Can't use an undefined value as a HASH reference In reply to
Cool, yeah that looks like it should be ok.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!