Is there something that's supposed to be in $_->[4] and it's missing, or it just doesn't have a value? That is, is there some bug besides the warning?
In cases where I know I might get undef values, I cheat a bit. Rather than make the code that comes after it do all sorts of backflips to test the values, I just make sure they all have a value before I use them. Since undef turns into the empty string for stringy things, I replace those values with the empty string.
my @array = map { defined $_ ? $_ : '' } @array[0..$last];
Notice that I use an array slice on the right hand side. You don't need to do it that way, but you need to go through all of the elements you think you should have, including trailing undef (or missing) elements on the end.
Alternately, you could pepper your code with a bunch of checks for defined(), but that can get in the way of whatever you are really trying to do.Other than that, I think you can get rid of a lot of code. It looks like you only want that first thing in @quotes, so you can just grab the first thing and ignore the rest. If there isn't anything there, you can die() right away (so you don't need $found), and the rest is just joining the elements. You could use this basic (and untested) structure:
use Finance::YahooQuote; # only use the first anon. array returned my( $quote ) = getcustomquote([ $symbol ], ["Float Shares"]); # stop if we didn't get back something die "No quote info. for symbol: $symbol" unless ref $quote; my $float = $quote->[1] ne "" ? join( ",", @$quote ) : "n/a"; print "$symbol Float Shares: $float";
Good luck :)
In reply to Re: A confusing Use of uninitialized value
by brian_d_foy
in thread A confusing Use of uninitialized value
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |