splice has no effect on scalar @list

Discussion in 'Perl Misc' started by Roger, Jun 1, 2004.

  1. Roger

    Roger Guest

    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/
    Roger, Jun 1, 2004
    #1
    1. Advertising

  2. Roger

    Roger Guest

    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/
    Roger, Jun 1, 2004
    #2
    1. Advertising

  3. Roger

    Roger Guest

    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/
    Roger, Jun 1, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark P
    Replies:
    2
    Views:
    380
    John Harrison
    Sep 20, 2005
  2. Juha Nieminen
    Replies:
    22
    Views:
    980
    Kai-Uwe Bux
    Oct 12, 2007
  3. Ben Pfaff
    Replies:
    2
    Views:
    337
    Ben Pfaff
    Feb 1, 2008
  4. Clint Olsen
    Replies:
    6
    Views:
    327
    Jeff 'japhy' Pinyan
    Nov 13, 2003
  5. Mark

    Replace scalar in another scalar

    Mark, Jan 27, 2005, in forum: Perl Misc
    Replies:
    4
    Views:
    144
    Arndt Jonasson
    Jan 27, 2005
Loading...

Share This Page