Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > how to report which specific variable is uninitialized

Reply
Thread Tools

how to report which specific variable is uninitialized

 
 
Tad J McClellan
Guest
Posts: n/a
 
      08-22-2008
Morfys <> wrote:
> On Aug 21, 6:53*pm, Sherm Pendley <spamt...@dot-app.org> wrote:
>> Morfys <morfyss...@gmail.com> writes:
>> > When running perl with the -w option, and executing a "print'" with
>> > about 30 variables, I get

>>
>> > Use of uninitialized value in print at at ./temp.pl line 9.

>>
>> > Is there any way to make perl report the exact variable name (out of
>> > the 30) that is not initialized?

>>
>> > ' use diagnostics;' doesn't help.

>>
>> Are you using strict? That requires you to declare your variables
>> before using them, so it will tell you if the "unitialized"
>> variable is really a variable whose name you've misspelled in the
>> call to print().

>
> Yes, I am using strict. The variables have all been declared.
>
>> > For various reasons, writings 30 statements of the form
>> > defined ($var) or warn "var is undefined";
>> > is difficult/a pain in my case.

>>
>> Honestly, I don't see why. Sure, it would be a pain to write all that
>> boilerplate all the time, but doing it once for debugging purposes
>> shouldn't be too much of a chore.

>
> Ok, I just thought there might some cool way to do it in perl with one
> line.



If you had chosen a better data structure to start with, then there
would some cool way to do it with two lines.


foreach my $varname ( sort keys %vars ) {
print "'$varname' is not defined\n" unless defined $vars{$varname};
}

But then you would have had to use hash keys in place of variable names.

Instead of
$sales_tax = stuff();
use
$vars{sales_tax} = stuff();


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
 
Reply With Quote
 
 
 
 
Peter Scott
Guest
Posts: n/a
 
      08-22-2008
On Thu, 21 Aug 2008 10:00:46 -0700, Morfys wrote:
> On Aug 21, 6:53*pm, Sherm Pendley <spamt...@dot-app.org> wrote:
>> Morfys <morfyss...@gmail.com> writes:
>> > When running perl with the -w option, and executing a "print'" with
>> > about 30 variables, I get

>>
>> > Use of uninitialized value in print at at ./temp.pl line 9.

>>
>> > Is there any way to make perl report the exact variable name (out of
>> > the 30) that is not initialized?

> Ok, I just thought there might some cool way to do it in perl with one
> line.


There is. The line is:

use 5.010;



--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
uninitialized constant Ruport::Report (NameError) Mmcolli00 Mom Ruby 1 04-21-2009 07:00 PM
Passing derived classes uninitialized variable to base class constructor !! PSN C++ 2 09-22-2006 04:14 PM
Eclipse bug: Doesn't check for uninitialized variables when there are "too many" variable declarations. Oliver Wong Java 11 04-19-2006 09:40 AM
How do you make sure a frameset is loaded? I'm trying to open a frameset in a new window which shows a specific html page in a specific frame ck388 Javascript 1 09-24-2003 08:32 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57