in reply to Re^2: I have a list expanding when I don't want it to
in thread I have a list expanding when I don't want it to

That's one way to do it. Or you could just delete the keys you don't want (re)included before you (re)populate them:

sub random { my ($user_input, $list) = @_; delete $list->{all}; delete $list->{keys}; $list->{'all'} = [ map { @$_ } values %{$list} ]; $list->{'keys'} = [ grep {$_ !~ /(?:all|keys)/} keys %{$list} ];

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^4: I have a list expanding when I don't want it to
by Lady_Aleena (Priest) on Nov 19, 2014 at 23:11 UTC

    I thought about using delete, however the doc suggested emptying the lists would be faster. If so I would prefer speed since I may be using these many times (100s of times even) in a script.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena

      First make it work (using the easiest to maintain code you can) then, only if you need to, make it faster.

      "Need to" requires that you have performed some sort of profiling so you know where things are slow. And before you "speed it up" write unit tests to make sure your speed up isn't at the expense of breaking the code (doing nothing can often be quite fast).

      Perl is the programming world's equivalent of English

        GrandFather, I added the first sentence to the list of Words of Wisdom (inelegantly called Notes from others) on my scratchpad so I will see them every time I look at it. Thanks for the nudge.

        No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
        Lady Aleena

        I down-voted you.

        Why?

        Because you are telling her, how she should program her code.

        And, (BTW) assuming (arrogantly) that she hasn't/didn't already profile both possibilities and choose appropriately.

        No attempt to help her. Just see the word (fast/er/est) and knee-jerk into patronizing dick mode.

        Subtext

        Assigning () to an array, causes the array to be emptied; but the AV* is retained; so is the hash key holding the reference to the AV*. Thus the HV* is unmodfied.

        Deleting the key(s) from the hash, not only empties (GCs) the elements of the array and modifies the size of the AV*; it also modifies the hash by removing a key value pair, only to recreate it immediately.

        She made the right choice. And I'm betting it wasn't by either guesswork or knee-jerk.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.