[Chicago-talk] Hash help
richard at rushlogistics.com
richard at rushlogistics.com
Tue Aug 11 08:16:07 PDT 2015
In the script below I can't figure out what I am doing wrong in building the $error_hash refrence. It only ends up containing the last missing parameter instead all that are missing (Lname and Email) can anyone help point out something that should be obvious to me?
Thanks
#!/usr/bin/perl;
use strict;
use warnings;
my $key;
my $hash;
my $value;
my $error_hash;
my %error_hash;
my %hash;
# create a hash
$hash = {
FName => 'Gregory',
LName => '',
Email => '',
Phone => '312-888-9999',
};
# check the hash for missing values.
while ( ($key, $value) = each %$hash) {
print "What we have in hash: $key => $value\n";
# test for an empty element
if (!defined($value) || $value eq '') {
print "NO " . $key . " WAS ENTERED\n";
$error_hash = { # create a hash with missing paramaters & msg
$key => ' is missing.',
}
}
}
# iterate the error hash
%hash = %$error_hash;
foreach my $k (keys %hash) {
print "$k: $hash{$k}\n";
}
More information about the Chicago-talk
mailing list