Help - Search - Member List - Calendar
Full Version: Use of uninitialized value... --> quit!
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Support our Sponsors!
Bryan R Harris
Often when debugging my scripts I get:

Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
....

-- filling up my terminal window. Is there any way to tell perl to quit
when it hits its first uninitialized value (or other) error?

- Bryan

Wiggins d'Anconia
Bryan R Harris wrote:
QUOTE

Often when debugging my scripts I get:

Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
...

-- filling up my terminal window.  Is there any way to tell perl to quit
when it hits its first uninitialized value (or other) error?


Yes. They are actually warnings instead of errors. You can either
silence them by turning off the uninitialized category, or you can set
that category of warnings to be fatal.

perldoc perllexwarn

For more on dealing with warnings. Optionally you could just check line
52 and see what variable you are using that is uninitialized and either
initialize it or check for a value before using it, which would be
fixing the problem rather than relieving the symptom.

QUOTE
- Bryan

Bryan R Harris
QUOTE
Bryan R Harris wrote:

Often when debugging my scripts I get:

Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
...

-- filling up my terminal window.  Is there any way to tell perl to quit
when it hits its first uninitialized value (or other) error?


Yes. They are actually warnings instead of errors. You can either
silence them by turning off the uninitialized category, or you can set
that category of warnings to be fatal.

perldoc perllexwarn

ralph 2057% perldoc perllexwarn
No documentation found for "perllexwarn".
ralph 2058%


QUOTE
For more on dealing with warnings. Optionally you could just check line
52 and see what variable you are using that is uninitialized and either
initialize it or check for a value before using it, which would be
fixing the problem rather than relieving the symptom.

That's what I end up doing -- I only asked because I'd rather perl quit when
it sees an uninitialized value.

Thanks!

- Bryan

Wiggins d'Anconia
Bryan R Harris wrote:
QUOTE

Bryan R Harris wrote:

Often when debugging my scripts I get:

Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
...

-- filling up my terminal window.  Is there any way to tell perl to quit
when it hits its first uninitialized value (or other) error?


Yes. They are actually warnings instead of errors. You can either
silence them by turning off the uninitialized category, or you can set
that category of warnings to be fatal.

perldoc perllexwarn


ralph 2057% perldoc perllexwarn
No documentation found for "perllexwarn".
ralph 2058%


Uh, that's probably not good. Does perldoc perl work?

In any case: http://perldoc.perl.org/perllexwarn.html

QUOTE


For more on dealing with warnings. Optionally you could just check line
52 and see what variable you are using that is uninitialized and either
initialize it or check for a value before using it, which would be
fixing the problem rather than relieving the symptom.


That's what I end up doing -- I only asked because I'd rather perl quit when
it sees an uninitialized value.

Gotcha.

QUOTE

Thanks!

- Bryan


Bryan R Harris
QUOTE
Bryan R Harris wrote:

Bryan R Harris wrote:

Often when debugging my scripts I get:

Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
Use of uninitialized value in print at line 52.
...

-- filling up my terminal window.  Is there any way to tell perl to quit
when it hits its first uninitialized value (or other) error?


Yes. They are actually warnings instead of errors. You can either
silence them by turning off the uninitialized category, or you can set
that category of warnings to be fatal.

perldoc perllexwarn


ralph 2057% perldoc perllexwarn
No documentation found for "perllexwarn".
ralph 2058%


Uh, that's probably not good. Does perldoc perl work?

In any case:  http://perldoc.perl.org/perllexwarn.html

Excellent, thanks!


QUOTE
For more on dealing with warnings. Optionally you could just check line
52 and see what variable you are using that is uninitialized and either
initialize it or check for a value before using it, which would be
fixing the problem rather than relieving the symptom.


That's what I end up doing -- I only asked because I'd rather perl quit when
it sees an uninitialized value.

Gotcha.

So if I understand right, all I need to do is put this at the top of my
script?

use warnings FATAL => 'all';

Is that doing what I want?

- B

Wiggins d'Anconia
Bryan R Harris wrote:
[snip]
QUOTE


So if I understand right, all I need to do is put this at the top of my
script?

use warnings FATAL => 'all';

Is that doing what I want?

- B


You tell us, based on my understanding of it and what you want it
should, but personally I have never done it :-)...

If you wanted just the uninitialized warnings to cause a cruel and
unbearable death then you could issue,

use warnings FATAL => 'uninitialized';

I suspect some of this could be dependent on the version of Perl as the
warnings pragma is *relatively* new.

http://danconia.org

Bryan R Harris
QUOTE
Bryan R Harris wrote:
[snip]


So if I understand right, all I need to do is put this at the top of my
script?

use warnings FATAL => 'all';

Is that doing what I want?

- B


You tell us, based on my understanding of it and what you want it
should, but personally I have never done it :-)...

Thanks, the "it should" was what I was wondering about.

And yes, it does seem to work. I hope it helps someone else, since this has
bothered me for a long time!

Thanks again!

- Bryan


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2005 Invision Power Services, Inc.