in reply to List or Scalar?

Ummm, if $term has the right value in it, why did you say
for( -5..@{$term} ) {
Why not just
for( -5..$term ) {
I think you got carried away with the specialized idiom of how to force values to be interpolated within strings, such as you used in
print "\$term is @{$term}\n";
But even here you could have just said
print "\$term is $term\n";

The value @{$term} is evaluating to an undefined value, which is somehow getting converted into a value of zero. If I say

for( -5..undef ) {
directly I get nasty warnings "Use of uninitialized value in foreach loop entry at hagen.pl line 36." Also if I use a variable with an undef value.

Why so?

Replies are listed 'Best First'.
Re: Re: List or Scalar?
by hagen (Friar) on Aug 27, 2003 at 08:20 UTC

    Thanks shenme... in the actual program the value is in a reference (as returned by the Win32::OLE module) - and is deref'ed (as I understand it) by the @{$term} syntax - it's come from a (ref to an) array of refs.

    What makes me think that this is correct is that the

     print "\$term is @{$term}\n"

    prints the value I want. However when I use the same @{$term} syntax in the range operator it doesn't seem to deref correctly - or I'm making some other sort of mistake.