Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > uninitialized value in concatenation ...

Reply
Thread Tools

uninitialized value in concatenation ...

 
 
Chris Conwell
Guest
Posts: n/a
 
      04-01-2004
I've been coding in Perl for some years now but here's a snippet of
code that's got me really stumped:

--------------------------------------------------------------------------------
Code
--------------------------------------------------------------------------------

3913 sub print_price_nicely {
3914 my ($model,$link,$price) = (@_);
3915 return unless ($price);
3916 if ($price) {
3917 if ($price eq "") {

--------------------------------------------------------------------------------

This is giving the error:

"Use of uninitialized value in concatenation (.) or string at
cgi/phones.pl line 3917."


How can the script reach line 3917 and then report "uninitialized
value"?!?!?

Thanks in advance,


Chris
 
Reply With Quote
 
 
 
 
Tore Aursand
Guest
Posts: n/a
 
      04-01-2004
On Thu, 01 Apr 2004 06:19:51 -0800, Chris Conwell wrote:
> 3913 sub print_price_nicely {
> 3914 my ($model,$link,$price) = (@_);
> 3915 return unless ($price);
> 3916 if ($price) {
> 3917 if ($price eq "") {
>
> This is giving the error:
>
> "Use of uninitialized value in concatenation (.) or string at
> cgi/phones.pl line 3917."


Give us the lines in the scope created on line 3917. One other thing is
that you don't need to check 'if ( $price )' and/or 'if ( $price eq "" )'
as long as you do 'return unless ( $price )'.

(But please remember that '$price' with a value of 0 also will be skipped,
even though I recall extremely cheap is also a price to pay...)




--
Tore Aursand <>
"Fighting terrorism is like being a goalkeeper. You can make a hundred
brilliant saves but the only shot that people remember is the one that
gets past you." -- Paul Wilkinson
 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      04-01-2004
Chris Conwell <> wrote in comp.lang.perl.misc:
> I've been coding in Perl for some years now but here's a snippet of
> code that's got me really stumped:
>
> --------------------------------------------------------------------------------
> Code
> --------------------------------------------------------------------------------
>
> 3913 sub print_price_nicely {
> 3914 my ($model,$link,$price) = (@_);
> 3915 return unless ($price);
> 3916 if ($price) {
> 3917 if ($price eq "") {
>
> --------------------------------------------------------------------------------
>
> This is giving the error:
>
> "Use of uninitialized value in concatenation (.) or string at
> cgi/phones.pl line 3917."
>
>
> How can the script reach line 3917 and then report "uninitialized
> value"?!?!?


Are there else-clauses?

Anno
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      04-01-2004
Chris Conwell <> wrote:
> I've been coding in Perl for some years now but here's a snippet of
> code that's got me really stumped:
>
> --------------------------------------------------------------------------------
> Code
> --------------------------------------------------------------------------------
>
> 3913 sub print_price_nicely {
> 3914 my ($model,$link,$price) = (@_);
> 3915 return unless ($price);
> 3916 if ($price) {
> 3917 if ($price eq "") {
>
> --------------------------------------------------------------------------------
>
> This is giving the error:



It is not an "error". It is a "warning". There is a difference.


> "Use of uninitialized value in concatenation (.) or string at
> cgi/phones.pl line 3917."
>
>
> How can the script reach line 3917 and then report "uninitialized
> value"?!?!?



Some things are warn()able and some things aren't.

Testing the "truth" of a variable whose value is undef
is not warnable (3915 & 3916).

Testing the "string equality" of a variable whose value is undef
against a constant string _is_ warnable (3917).


--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      04-01-2004
On Thu, 1 Apr 2004, Tad McClellan wrote:

> Chris Conwell <> wrote:
> > I've been coding in Perl for some years now but here's a snippet of
> > code that's got me really stumped:
> >
> > --------------------------------------------------------------------------------
> > Code
> > --------------------------------------------------------------------------------
> >
> > 3913 sub print_price_nicely {
> > 3914 my ($model,$link,$price) = (@_);
> > 3915 return unless ($price);
> > 3916 if ($price) {
> > 3917 if ($price eq "") {
> >
> > --------------------------------------------------------------------------------
> >
> > This is giving the error:

>
> It is not an "error". It is a "warning". There is a difference.
>
> > "Use of uninitialized value in concatenation (.) or string at
> > cgi/phones.pl line 3917."
> >
> > How can the script reach line 3917 and then report "uninitialized
> > value"?!?!?

>
> Some things are warn()able and some things aren't.
>
> Testing the "truth" of a variable whose value is undef
> is not warnable (3915 & 3916).
>
> Testing the "string equality" of a variable whose value is undef
> against a constant string _is_ warnable (3917).


None of which gives any kind of answer. The point of the OP's question is
that clearly Perl believes on line 3915 that $price has a true value,
and on 3916 that $price has a true value. But the compilation warning
he's getting indicates that $price is unintialized on line 3917.

No obviously, this isn't correct, and the warning isn't reporting the
correct line. But the statements you posted have nothing to do with the
problem at hand.

Paul Lalli
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      04-01-2004
>>>>> "CC" == Chris Conwell <> writes:

CC> 3913 sub print_price_nicely {

i hope you don't actually use 1 char indents. 2 is bad enough with 3 or
4 being a good minimum.

CC> 3914 my ($model,$link,$price) = (@_);

no need for () around @_. the left side provides the list context and
the () are not doing anything.

CC> 3915 return unless ($price);

no need for () there, any expression is fine. only if statements (as
below) need () for proper syntax.

CC> 3916 if ($price) {

why are you again testing $price when you just returned if you have no
price?

CC> 3917 if ($price eq "") {

CC> This is giving the error:

CC> "Use of uninitialized value in concatenation (.) or string at
CC> cgi/phones.pl line 3917."

CC> How can the script reach line 3917 and then report "uninitialized
CC> value"?!?!?

first off, you should never have a source file with so much code in
it. break it up into smaller files as it will make life easier for you
in many ways.

secondly, i bet your line numbering is at fault. how did you determine
those line numbers? perl may have a different view of what line numbers
are than you (or the program you used) do. did your line numbering thing
count long wrapped lines as 1 or multiple lines? perl counts them as one
line.

uri
 
Reply With Quote
 
Chris Conwell
Guest
Posts: n/a
 
      04-01-2004
Tore Aursand <> wrote in message news:<>.. .

> Give us the lines in the scope created on line 3917. One other thing is
> that you don't need to check 'if ( $price )' and/or 'if ( $price eq "" )'
> as long as you do 'return unless ( $price )'.


The 'return unless ( $price )' was only added as a debugging line
after getting completely confused as to how the error message can
happen (and then getting more confused when the error continued .

> (But please remember that '$price' with a value of 0 also will be skipped,
> even though I recall extremely cheap is also a price to pay...)


Yes, if $price is zero then an "elsif" further on deals with it - see
next post.

Thanks for taking an interest in this problem.

Chris.
 
Reply With Quote
 
Chris Conwell
Guest
Posts: n/a
 
      04-01-2004
(Anno Siegel) wrote in message news:<c4hbqn$ce3$>...
> > How can the script reach line 3917 and then report "uninitialized
> > value"?!?!?

>
> Are there else-clauses?


Yes, the script continues (where "..." signifies irrelevant code to
output data) :

--------------------------------------------------------------------------------

3913 sub print_price_nicely {
3914 my ($model,$link,$price) = (@_);
3915 return unless ($price);
3916 if ($price) {
3917 if ($price eq "") {
....
3920 }
3921 elsif ($price =~ /TBC/i) {
....
3925 }
3926 elsif ($this_index =~ /INDEXU/) {
....
3929 }
3930 else {
....
3935 }
3936 }

--------------------------------------------------------------------------------

Are you thinking that the error is actually on one of the "elsif"
statements and is being incorrectly flagged as the first "if" line?

Thanks for your help,


Chris.
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      04-01-2004
>>>>> "CC" == Chris Conwell <> writes:

>> Are there else-clauses?

CC> 3916 if ($price) {
CC> 3917 if ($price eq "") {
CC> ...
CC> 3920 }
CC> 3921 elsif ($price =~ /TBC/i) {
CC> ...
CC> 3925 }
CC> 3926 elsif ($this_index =~ /INDEXU/) {
CC> ...
CC> 3929 }
CC> 3930 else {
CC> ...
CC> 3935 }
CC> 3936 }

CC> --------------------------------------------------------------------------------

CC> Are you thinking that the error is actually on one of the "elsif"
CC> statements and is being incorrectly flagged as the first "if" line?

that is very possible. perl does sometimes report line numbers in odd
places and this could be one of them. so investigate $this_index's value

but i also asked if the way you generated line numbers are accurate and
handled long lines. you never asnwered that.

uri
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      04-01-2004
Paul Lalli <> wrote:
> On Thu, 1 Apr 2004, Tad McClellan wrote:


[ snip my drivel ]

> But the statements you posted have nothing to do with the
> problem at hand.



Oops.

Sorry.


--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas
 
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
(Newbie) Use of uninitialized value in concatenation (.) or string Jesse Cary Perl Misc 2 10-15-2004 09:47 PM
Use of uninitialized value in concatenation smartins68 Perl 1 06-09-2004 05:46 AM
Re: Use of uninitialized value in concatenation (.) or string Error Sukhbir Dhillon Perl 1 04-05-2004 02:31 AM
Use of uninitialized value in concatenation (.) or string S Perl Misc 3 02-03-2004 09:54 PM
Use of uninitialized value in concatenation (.) at register.pl line 38, <STDIN> line 10. G Kannan Perl 1 10-11-2003 11:58 AM



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