Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Use of uninitialized value in array element

by Fastolfe (Vicar)
on Jul 12, 2002 at 15:56 UTC ( #181321=note: print w/ replies, xml ) Need Help??


in reply to Use of uninitialized value in array element

What if one of these conditions fails:

my ($ts,$cat) = $vals[0] =~ /TS(\d+)(.+)$/; ... for(0..$#cats) { if ($cats[$_] =~ /$cat/) { $j = $_ } } for(@{$groups[0]}) { if ($ts == $_) { $i = 0 } } for(@{$groups[1]}) { if ($ts == $_) { $i = 1 } } for(@{$groups[2]}) { if ($ts == $_) { $i = 2 } }
It looks like somehow, somewhere, either $i or $j is left undefined. Add some print statements in your loops that print out the values of your various variables and check that your assumptions are valid here. Could there be an empty line in your input?


Comment on Re: Use of uninitialized value in array element
Select or Download Code
Re: Re: Use of uninitialized value in array element
by TexasTess (Beadle) on Jul 12, 2002 at 21:37 UTC
    Undefined how? If the $ is left off it's not undefined..it's been my experience that it's a "bareword".

    TexasTess
    "Great Spirits Often Encounter Violent Opposition From Mediocre Minds" --Albert Einstein It is the practice of downvoting any efforts to comment or help that will be the downfall of the rating system at this site. When individuals are downvoted and/or ridiculed for the smallest effort to try to understand a post or help with a problem then it doesn't make them want to try to be a positive entity at this website, it makes them never want to return.
      The presence of a dollar-sign is not the issue. The value of the variables at this point in the program is what's suspect:
      my $a; # undef my $b = 1; my @array = ( [4, 3], [2, 1], ); print $array[$b]->[$b]; # 1 print $array[$b]->[$a]; # Use of uninitialized value in array element, + but prints 2 print $array[$a]->[$b]; # Use of uninitialized value in array element, + but prints 3
      The undefined value has a numeric value of 0, so it all "works" because of Perl's DWIM nature, but through the grace of warnings we know that something is amiss if we expect that our index variables should always have a numeric value.
        Thanks for the clarification, I had NOT Experienced this in any of my perl works....and as a result am doomed for perl monk dumbassdom....

        TexasTess
        "Great Spirits Often Encounter Violent Opposition From Mediocre Minds" --Albert Einstein

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://181321]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2014-10-21 02:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (95 votes), past polls