[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#2254: perl doesn't initialize variable to 0 or something



'Mark W. Eichin wrote:'
>
>have you tried perl -w on the code? It indicates "use of uninitialized
>value" on lines 27 and 36... note that on 27, the first time through,
>$itemind is undef, not 0, and $price_array{undef, 1} is not the same
>as $price_array{0, 1}. Perhaps you're being misled by the fact that ++
>on an uninitialized value gives 1? or that {} is taking string values,
>not numeric values?

I did use perl -w and found the number of problems ... intimidating
(and print statements not -w allowed me to find the exact problem!).  I
wrote this script many moons ago under perl4 and Slackware (and I made
very careful checks at that time for data correctness).  Then a
customer noticed that there were problems which I eventually tracked to
the code fragment I posted.  I did check the man page before posting:
in perlsyn(1p) I found "All uninitialized user-created objects are
assumed to start with a null or 0 value until they are defined by some
explicit operation such as assignment.  (Though you can get warnings
about the use of undefined values if you like.)".  It sounded to me
like perl5 preserves perl4 and awk's treatment of uninitialized
variables.  That's the main reason I thought it was a bug in Perl.  It
could be a bug in the documentation which could say upfront that perl4
and perl5 can give very unexpected results when using uninitialized
variables, but I did not find any such warning in my review of the
docs.

>I don't know if this is a documented perl4/perl5 difference, but given
>the output of perl -w, it doesn't seem surprising, at least to me...

I rechecked and found no indication in the most obvious man pages that
there are some cases where unitialized variables lead to unexpected
results in Perl5 over Perl4.  Though I didn't read EVERY man page in
the perl5 set :(

--
Christopher J. Fearnley            |    UNIX SIG Leader at PACS
cjf@netaxs.com                     |    (Philadelphia Area Computer Society)
http://www.netaxs.com/~cjf         |    Design Science Revolutionary
ftp://ftp.netaxs.com/people/cjf    |    Explorer in Universe
"Dare to be Naive" -- Bucky Fuller |    Linux Advocate



Reply to: