Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Use of uninitialized value

by The Mad Hatter (Priest)
on Nov 07, 2004 at 03:37 UTC ( #405846=note: print w/ replies, xml ) Need Help??


in reply to Use of uninitialized value

Like pg said, you need to show us the rest of your code. In lieu of that, I'm guessing you call this sub actions before the initializing code

my $num = 0; my $status_count = 0; my $status_goal = 0;
has been run.

For example, examine how the following code runs:

use strict; use warnings; print_foo(); my $foo = "bar\n"; sub print_foo { print $foo; } print_foo();

The first call to the sub throws the uninitialized error because the statement my $foo = "bar\n"; hasn't been executed yet. By the second call, that statement has been executed, so there is no warning.


Comment on Re: Use of uninitialized value
Select or Download Code
Re^2: Use of uninitialized value
by ikegami (Pope) on Nov 07, 2004 at 17:15 UTC

    That can be fixed as follows by reordering the statememnts, or by wrapping the my (and therefore the sub) in a BEGIN block:

    BEGIN { my $foo = "bar\n"; sub print_foo { print $foo; } }
Re^2: Use of uninitialized value
by rev_1318 (Chaplain) on Nov 07, 2004 at 22:25 UTC
    That would be my guess also. To avoid this kind of errors, I advise against the use of 'globally used lexicals'. use 'use constant' for constants or pass them to the subroutine and pass variables by reference. Paul

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2014-04-20 22:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (488 votes), past polls