[Chicago-talk] Hash help

Richard Reina gatorreina at gmail.com
Tue Aug 11 08:27:20 PDT 2015


Thanks guys.  Painful to be so clueless.  Many thanks also for the quick
reply.

2015-08-11 10:21 GMT-05:00 Shawn Carroll <shawn.c.carroll at gmail.com>:

> 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
>
>
>
> _______________________________________________
> 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/27ce7afb/attachment.html>


More information about the Chicago-talk mailing list