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/"