[Chicago-talk] Hash help

Kate Kirby kirbyk at gmail.com
Tue Aug 11 08:18:02 PDT 2015


Change your inner thing to:

$error_hash->{ $key } = 'is missing';

It's resetting the whole hash each time rather than assigning a value to a
key.

-- Kate

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/1cdd635e/attachment.html>


More information about the Chicago-talk mailing list