Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > splice has no effect on scalar @list

Reply
Thread Tools

splice has no effect on scalar @list

 
 
Roger
Guest
Posts: n/a
 
      06-01-2004

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?

--
Use our news server 'news.foorum.com' from anywhere.
More details at: http://nnrpinfo.go.foorum.com/
 
Reply With Quote
 
 
 
 
Roger
Guest
Posts: n/a
 
      06-01-2004

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'.

--
Use our news server 'news.foorum.com' from anywhere.
More details at: http://nnrpinfo.go.foorum.com/
 
Reply With Quote
 
 
 
 
Roger
Guest
Posts: n/a
 
      06-01-2004

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.

--
Use our news server 'news.foorum.com' from anywhere.
More details at: http://nnrpinfo.go.foorum.com/
 
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
Replace scalar in another scalar Mark Perl Misc 4 01-27-2005 02:48 PM
Shorthand for($scalar) loops and resetting pos($scalar) Clint Olsen Perl Misc 6 11-13-2003 12:50 AM



Advertisments