[Omaha.pm] silly warnings

Theodore Katseres tedkat at gmail.com
Wed Jan 14 14:54:18 PST 2009


On Wed, Jan 14, 2009 at 4:32 PM, Dan Linder <dan at linder.org> wrote:

> Wow, did I stump all the Perl experts, or did everyone go on vacation? ;-)
>

I'm not an expert but I give it a go :)

Another thought I had: Is it possible to "define $hash{$key}" manually
> without assigning a value to it?  (i.e. the opposite of "undef $hash{$key}")
>

Yes but a warning will pop up in it's place "Useless use of hash element in
void context"


>  Dan
> On Tue, Jan 13, 2009 at 9:07 AM, Dan Linder <dan at linder.org> wrote:
>
>> Jay Hannah <jay at jays.net> wrote:
>> > next if ($audit->{$date} && $audit->{$date}->{$hotel} &&
>> $audit->{$date}->{$hotel} > 0);
>>
>> Sterling Hanenkamp wrote:
>> > I usually prefer:
>> > next if ($audit->{$date}{$hotel} || 0) > 0;
>>
>> Ok, I'm getting a similar issue with this bit of code:
>> 55            } else {
>> 56                ($value, $parm)=split(/\s+/,$line,2);
>> 57                $myhash1{$section_name}{$parm} = $value;
>> 58            }
>>
>> Line 57 is spitting a lot of "Use of unitialized value in hash element"
>> warnings -- I'm pretty certain it's because of the newly defined %myhash1hash instantly having the $section_name and $parm keys used right away.
>
>
Make sure that each var in the hash key is defined.


>> I tried putting in these lines between 56 and 57:
>> 55            } else {
>> 56                ($value, $parm)=split(/\s+/,$line,2);
>
>                                            $parm = '' unless ( defined
$parm );
                                           $section_name = '' unless (
defined $parm );

> 57                ($myhash1{$section_name} || 0);
>> 58                ($myhash1{$section_name}{$parm} || 0);
>> 59                $myhash1{$section_name}{$parm} = $value;
>> 60            }
>> ...but the warnings still persist.
>>
>> Aside from turning off warnings for these lines, is there a better way to
>> handle this?  Should I be pre-loading the "$myhash1{$section_name}" branch
>> first before adding the "{$parm}" branch to it?
>
>
 That will take care of the warnings but it might hide a bug too :P


-- 
Ted Katseres
     ||=O=||
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/omaha-pm/attachments/20090114/631cfcdd/attachment.html>


More information about the Omaha-pm mailing list