M
mcardeiro
Hello
I have a line of code that is creating an entry in a mysql table using
DBI. I have the record values for the insert in a hash reference. A
separate array holds information about the table structure so that
when I do my insert I map the hash ref using the array so only
relevant values are entered into the execute statement and they are in
the proper order.
It works exactly as it is supposed to but I keep getting a warning
from perl "Useless use of a constant in void context at /var/www/web1/
lib/TS.pm line 1258."
I am ignoring it because the code works, but figure I'll throw it out
there in case I am doing something boneheaded.
heres some code fragments:
#######################################################################################
###holds info about the structure of the table and is used to verify
data before entry
########################################################################################
our @userTableOrder = (
{ 'name' => 'username',
'required' => 1,
'regexp' => '^[\w\d]{1,15}$',
},
{ 'name' => 'password',
'required' => 1,
},
{ 'name' => 'authorize',
'required' => 1,
'regexp' => '^[\d]+$',
},
);
############################
### record to be inserted
##########################
my $newUser = {
'username' => 'mcardeiro',
'password' => 'booba',
'authorize' => 3,
'workgroup' => 'philadelphia',
};
############################
### DBI stuff
##########################
$sth = $dbh->prepare("INSERT INTO users VALUES (?,?,?")
|| error_page("cant prepare insert statement at userEntry: $dbh-
#############################################################
##### the code below is causing the warning...why?
#########################################################
$sth->execute( map {$newUser->{$_->{'name'}}} @userTableOrder)
|| error_page("cant execute insert statement at userEntry: $dbh-
I have a line of code that is creating an entry in a mysql table using
DBI. I have the record values for the insert in a hash reference. A
separate array holds information about the table structure so that
when I do my insert I map the hash ref using the array so only
relevant values are entered into the execute statement and they are in
the proper order.
It works exactly as it is supposed to but I keep getting a warning
from perl "Useless use of a constant in void context at /var/www/web1/
lib/TS.pm line 1258."
I am ignoring it because the code works, but figure I'll throw it out
there in case I am doing something boneheaded.
heres some code fragments:
#######################################################################################
###holds info about the structure of the table and is used to verify
data before entry
########################################################################################
our @userTableOrder = (
{ 'name' => 'username',
'required' => 1,
'regexp' => '^[\w\d]{1,15}$',
},
{ 'name' => 'password',
'required' => 1,
},
{ 'name' => 'authorize',
'required' => 1,
'regexp' => '^[\d]+$',
},
);
############################
### record to be inserted
##########################
my $newUser = {
'username' => 'mcardeiro',
'password' => 'booba',
'authorize' => 3,
'workgroup' => 'philadelphia',
};
############################
### DBI stuff
##########################
$sth = $dbh->prepare("INSERT INTO users VALUES (?,?,?")
|| error_page("cant prepare insert statement at userEntry: $dbh-
errstr");
#############################################################
##### the code below is causing the warning...why?
#########################################################
$sth->execute( map {$newUser->{$_->{'name'}}} @userTableOrder)
|| error_page("cant execute insert statement at userEntry: $dbh-