[Chicago-talk] Hash help
Shawn Carroll
shawn.c.carroll at gmail.com
Tue Aug 11 08:21:43 PDT 2015
You are recreating your error_hash each time you try to add to it. Instead:
$error_hash{$key} = 'is missing';
shawn.c.carroll at gmail.com
Software Engineer
Soccer Referee
On Tue, Aug 11, 2015 at 10:16 AM, <richard at rushlogistics.com> wrote:
> 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";
>
> }
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20150811/070f635c/attachment-0001.html>
More information about the Chicago-talk
mailing list