Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

period in strings

by kc (Initiate)
on Apr 27, 2010 at 21:46 UTC ( [id://837204]=perlquestion: print w/replies, xml ) Need Help??

kc has asked for the wisdom of the Perl Monks concerning the following question:

Hi! i'm relatively new to perl and keep getting this warning:

Use of uninitialized value in string eq at test.pl line 40.

foreach my $key (@keys) {
if (($key->{'att'}->{'for'} eq 'node') && ($key->{'att'}->{'yfiles.type'} eq 'nodegraphics')){ #line 40 here
$nodeD = $key->{'att'}->{'id'};
} elsif (($key->{'att'}->{'for'} eq 'edge') && ($key->{'att'}->{'yfiles.type'} eq 'edgegraphics')){
$edgeD = $key->{'att'}->{'id'};
}
}
i wonder if it is the period in the 'yfiles.type' that is causing the warning and how i can get rid of it?

Replies are listed 'Best First'.
Re: period in strings
by kennethk (Abbot) on Apr 27, 2010 at 21:54 UTC
    The issue is not the period, per se, but that the nested hash structure is uninitialized for either $key->{'att'}->{'for'} or $key->{'att'}->{'yfiles.type'}. I would suggest you use Data::Dumper to examine your @keys structure before you reach the loop to see if the data content matches your expectations. Inserting the following before your foreach loop should suffice:

    use Data::Dumper; print Dumper \@keys;

    On a side note, please wrap posted code in <code> tags to maintain formatting, as per Writeup Formatting Tips or Markup in the Monastery. And welcome to the Monastery.

Re: period in strings
by apl (Monsignor) on Apr 27, 2010 at 22:24 UTC
    You never need to "wonder". Googling Perl uninitialized value would have pointed you towards something like this.
Re: period in strings
by doug (Pilgrim) on Apr 28, 2010 at 12:55 UTC

    Ouch, That is ugly. Next time try something like

     my %field = %{ $key->{att} };

    or maybe

    my $for = $key->{att}->{'for'}; my $type = $key->{att}->{yfiles.type};

    to reduce the amount of dereferencing. It is really easy to misread all that stuff.

    - doug

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://837204]
Approved by kennethk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-18 13:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found