[23538] in Perl-Users-Digest
Perl-Users Digest, Issue: 5746 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 3 21:11:56 2003
Date: Mon, 3 Nov 2003 18:10:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 3 Nov 2003 Volume: 10 Number: 5746
Today's topics:
Verbose warnings (Seebs)
Re: Verbose warnings <grazz@pobox.com>
Re: Verbose warnings <hexkid@hotpop.com>
Re: Verbose warnings (Tad McClellan)
Re: Verbose warnings <tassilo.parseval@rwth-aachen.de>
Re: Verbose warnings <grazz@pobox.com>
Re: Verbose warnings (Malcolm Dew-Jones)
Re: Verbose warnings (Seebs)
Re: Verbose warnings <REMOVEsdnCAPS@comcast.net>
Re: Verbose warnings (Tad McClellan)
Re: What am I doing wrong?! <grazz@pobox.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 03 Nov 2003 20:28:40 GMT
From: seebs@plethora.net (Seebs)
Subject: Verbose warnings
Message-Id: <3fa6ba78$0$1100$3c090ad1@news.plethora.net>
Is there any way to find out WHICH variable is uninitialized, short of
breaking a line up into bunches of single lines?
I inherited a HUGE script full of lines that look roughly like
$value = "$value1$value2$value3<a href="$value4"
fgcolor="$value5">$value6</a><font size="$value7">..."
which are trying to build HTML from *HORDES* of values.
I probably have, say, five hundred of these little buggers to catch.
I would be *deleriously* happy to discover a warning switch that would
cause perl to say "Use of uninitialized value (variable $value3)" or
something similar.
Perl is 5.6.1; I could probably use 5.8 without much trouble, but I don't
want to switch right now if I don't have to.
-s
--
Copyright 2003, all wrongs reversed. Peter Seebach / seebs@plethora.net
http://www.seebs.net/log/ - YA blog. http://www.seebs.net/ - homepage.
C/Unix wizard, pro-commerce radical, spam fighter. Boycott Spamazon!
Consulting, computers, web hosting, and shell access: http://www.plethora.net/
------------------------------
Date: Mon, 03 Nov 2003 21:20:54 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: Verbose warnings
Message-Id: <WEzpb.1788$%7.1704@nwrdny01.gnilink.net>
Seebs <seebs@plethora.net> wrote:
> Is there any way to find out WHICH variable is uninitialized, short of
> breaking a line up into bunches of single lines?
I don't think so. The warning should say "Undefined value", and
not all values (scalars) are named variables:
% perl -we 'print undef'
Use of uninitialized value in print at -e line 1
Probably the best thing to do: validate those variables when you
set them...
--
Steve
------------------------------
Date: 3 Nov 2003 21:42:54 GMT
From: Pedro <hexkid@hotpop.com>
Subject: Re: Verbose warnings
Message-Id: <bo6i4t$18tlmr$1@ID-203069.news.uni-berlin.de>
Steve Grazzini wrote:
> Seebs <seebs@plethora.net> wrote:
>> Is there any way to find out WHICH variable is uninitialized, short of
>> breaking a line up into bunches of single lines?
>
> I don't think so. The warning should say "Undefined value", and
> not all values (scalars) are named variables:
>
> % perl -we 'print undef'
> Use of uninitialized value in print at -e line 1
Using perl 5.8.1
$ perl -we 'print $xyz;'
Name "main::xyz" used only once: possible typo at -e line 1.
Use of uninitialized value in print at -e line 1.
--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
------------------------------
Date: Mon, 3 Nov 2003 15:53:11 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Verbose warnings
Message-Id: <slrnbqdji7.h5n.tadmc@magna.augustmail.com>
Seebs <seebs@plethora.net> wrote:
> Is there any way to find out WHICH variable is uninitialized, short of
> breaking a line up into bunches of single lines?
Yes, if they are package (dynamic) variables.
Are they package or lexical variables?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 3 Nov 2003 22:02:22 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Verbose warnings
Message-Id: <bo6j9e$b0k$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Tad McClellan:
> Seebs <seebs@plethora.net> wrote:
>> Is there any way to find out WHICH variable is uninitialized, short of
>> breaking a line up into bunches of single lines?
>
>
> Yes, if they are package (dynamic) variables.
How so?
ethan@ethan:~$ perl -w
use vars qw/$c $d $e $f/;
$e = 1;
print "$c;$d;$e;$f\n";
__END__
Use of uninitialized value in concatenation (.) or string at - line 3.
Use of uninitialized value in concatenation (.) or string at - line 3.
Use of uninitialized value in concatenation (.) or string at - line 3.
;;1;
versus
ethan@ethan:~$ perl -w
my ($c,$d,$e,$f);
$e = 1;
print "$c;$d;$e;$f\n";
__END__
Use of uninitialized value in concatenation (.) or string at - line 3.
Use of uninitialized value in concatenation (.) or string at - line 3.
Use of uninitialized value in concatenation (.) or string at - line 3.
;;1;
At least up to (and including) 5.8.1, the behaviour seems to be
independent from using lexicals or dynamic variables.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Mon, 03 Nov 2003 22:09:58 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: Verbose warnings
Message-Id: <WmApb.43532$294.31211@nwrdny03.gnilink.net>
Pedro <hexkid@hotpop.com> wrote:
> Steve Grazzini wrote:
> > Seebs <seebs@plethora.net> wrote:
> >> Is there any way to find out WHICH variable is uninitialized
> >
> > I don't think so. The warning should say "Undefined value", and
> > not all values (scalars) are named variables:
>
> Using perl 5.8.1
> $ perl -we 'print $xyz;'
>
> Name "main::xyz" used only once: possible typo at -e line 1.
> Use of uninitialized value in print at -e line 1.
Those are two unrelated (and ancient -- nothing new in 5.8.1) warnings.
The OP wanted the "uninitialized" warning to include the variable name,
and that's what I don't think is supported.
--
Steve
------------------------------
Date: 3 Nov 2003 14:10:28 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Verbose warnings
Message-Id: <3fa6d254@news.victoria.tc.ca>
Seebs (seebs@plethora.net) wrote:
: Is there any way to find out WHICH variable is uninitialized, short of
: breaking a line up into bunches of single lines?
: I inherited a HUGE script full of lines that look roughly like
: $value = "$value1$value2$value3<a href="$value4"
: fgcolor="$value5">$value6</a><font size="$value7">..."
: which are trying to build HTML from *HORDES* of values.
: I probably have, say, five hundred of these little buggers to catch.
: I would be *deleriously* happy to discover a warning switch that would
: cause perl to say "Use of uninitialized value (variable $value3)" or
: something similar.
: Perl is 5.6.1; I could probably use 5.8 without much trouble, but I don't
: want to switch right now if I don't have to.
perl -MO=Deparse,-q
might reproduce your program in a format where it would be easier to
automate the adding of line breaks etc.
k
------------------------------
Date: 04 Nov 2003 01:24:10 GMT
From: seebs@plethora.net (Seebs)
Subject: Re: Verbose warnings
Message-Id: <3fa6ffba$0$1096$3c090ad1@news.plethora.net>
In article <slrnbqdji7.h5n.tadmc@magna.augustmail.com>,
Tad McClellan <tadmc@augustmail.com> wrote:
>Seebs <seebs@plethora.net> wrote:
>> Is there any way to find out WHICH variable is uninitialized, short of
>> breaking a line up into bunches of single lines?
>Yes, if they are package (dynamic) variables.
>Are they package or lexical variables?
Package variables. Which are, currently, set and reused across two different
pieces of code, one of which is incorporated with a 'require' statement.
(No, it's not a module; it's just a chunk of code.)
-s
--
Copyright 2003, all wrongs reversed. Peter Seebach / seebs@plethora.net
http://www.seebs.net/log/ - YA blog. http://www.seebs.net/ - homepage.
C/Unix wizard, pro-commerce radical, spam fighter. Boycott Spamazon!
Consulting, computers, web hosting, and shell access: http://www.plethora.net/
------------------------------
Date: Mon, 03 Nov 2003 19:42:55 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Verbose warnings
Message-Id: <Xns9428D2C97DE58sdn.comcast@216.196.97.136>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
seebs@plethora.net (Seebs) wrote in news:3fa6ba78$0$1100$3c090ad1
@news.plethora.net:
> Is there any way to find out WHICH variable is uninitialized, short of
> breaking a line up into bunches of single lines?
>
> I inherited a HUGE script full of lines that look roughly like
>
> $value = "$value1$value2$value3<a href="$value4"
> fgcolor="$value5">$value6</a><font size="$value7">..."
> which are trying to build HTML from *HORDES* of values.
>
> I probably have, say, five hundred of these little buggers to catch.
500 statements? or 500 variables?
The solution that occurs to me is to tie each variable to a class that
gives more information when its (undefined) value is fetched. Something
like:
package MoreWarnings;
use Carp;
sub TIESCALAR
{
my ($class, $name) = shift;
my ($file, $line, $pkg) = caller;
bless { name => $name,
value=> undef,
file => $file,
line => $line,
pkg => $pkg }, $class;
}
sub STORE
{
my $self = shift;
$self->{value} = shift;
}
sub FETCH
{
my $self;
if (!defined $self->{value})
{
carp "Variable $self->{name} undefined";
# optionally add information about where it was tied
}
return $self->{value};
}
And then every place there was a
my $foo;
replace it with
tie my $foo, 'MoreWarnings', 'foo';
- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBP6cELmPeouIeTNHoEQKiYgCcCs1wWqQhCfUt8lEObMaS9CAx0fUAoOnX
qbsRa9SKhZbGja0zf9cz1/ui
=mk7O
-----END PGP SIGNATURE-----
------------------------------
Date: Mon, 3 Nov 2003 19:47:06 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Verbose warnings
Message-Id: <slrnbqe18q.hbl.tadmc@magna.augustmail.com>
Tassilo v. Parseval <tassilo.parseval@rwth-aachen.de> wrote:
> Also sprach Tad McClellan:
>
>> Seebs <seebs@plethora.net> wrote:
>>> Is there any way to find out WHICH variable is uninitialized, short of
>>> breaking a line up into bunches of single lines?
>>
>>
>> Yes, if they are package (dynamic) variables.
>
> How so?
I think you were thinking that I was answering the question
that I trimmed, rather than the question that I quoted?
I trimmed the other one because its answer wasn't interesting. :-)
> ethan@ethan:~$ perl -w
> use vars qw/$c $d $e $f/;
> $e = 1;
> print "$c;$d;$e;$f\n";
> __END__
> Use of uninitialized value in concatenation (.) or string at - line 3.
> Use of uninitialized value in concatenation (.) or string at - line 3.
> Use of uninitialized value in concatenation (.) or string at - line 3.
> ;;1;
> At least up to (and including) 5.8.1, the behaviour seems to be
> independent from using lexicals or dynamic variables.
Yes, but if they are dynamic variables, then we can use symrefs
and stay "short of breaking a line up into bunches of single lines".
[tadmc@temp]$ perl -w
use vars qw/$c $d $e $f/;
$e = 1;
print "\$$_ is undef\n" for grep !defined $$_, qw/ c d e f /;
__END__
$c is undef
$d is undef
$f is undef
:-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 03 Nov 2003 19:29:33 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: What am I doing wrong?!
Message-Id: <x0ypb.80523$1C5.79423@nwrdny02.gnilink.net>
Tore Aursand <tore@aursand.no> wrote:
> On Mon, 03 Nov 2003 12:37:27 +0000, Anno Siegel wrote:
> > But the code above isn't just bad, or hard to read, it's *wrong*.
>
> Excactly my point.
Fine -- but the OP also said that "for (@array)" wasn't working, so
it's hard to see how "foreach (@array)" could help.
--
Steve
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 5746
***************************************