splice has no effect on scalar @list

R

Roger

Greetings,

I *thought* I knew how to use 'scalar' and 'splice'...

while( $num < scalar(@odd_num) )
splice (@list,$odd_num[$num],0,$field_num[$num]);

#'odd_num' and 'field_num' are arrays loaded with integer index values, use here
in #a scalar context, the problem is after each call to splice, the array 'list'
#does not grow ... next line of code....

$num++;
my $range = scalar @list; #stuck in here for debugging

#Here the value of 'range' never changes from the entry into the while loop.
#yet in the debugger, I see @list growing with each iteration!!!!!
#It's making crazy!

Question, why isn't the call to 'scalar' reflecting the new size of '@list' with
each iteration?
 
R

Roger

sorry!!!!!!!!

I was declaring my debugger variable inside the while loop using 'my' and a
scoping issue I don't fully understand was at play.
I took away the 'my' declarative modifier (??) and it works fine, obviously not
using strict.

I still don't know why using 'my' would affect the execution in that way. It's
not trying to modify @list only count it, so why should it matter if it was
local aka 'my' not the real 'local'... to the while body?

It does work now without 'my'.
 
R

Roger

OK just ignore me.

I had previously declared 'range' above and the debuggers output was reflecting
the first 'range'


as usual the computer was right.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top