in reply to Re^3: Remove redundency from an array
in thread Remove redundency from an array

First, local *_ does work if you put it in the do block like jdporter said.

Secondly, local $_ won't work. It'll compile, but that doesn't count for anything if it doesn't do what needs to be done. We want to protect the parent's %_.

Replies are listed 'Best First'.
Re^5: Remove redundency from an array
by mwah (Hermit) on Sep 24, 2007 at 19:47 UTC
    ikegami: 
    - local *_ does work if you put it in the do block like jdporter said
    - ... want to protect the parent's %_

    * Did you test this with the sub{}-example I provided in
       order to show context dependency?
    * where would preservation of %_ (jdporter mentioned $_)
       usually be of some importance?

    Regards & thanks
    mwa

      Did you test this with the sub{}-example I provided in order to show context dependency?

      Nope. I know it does exactly what you said it does. What it doesn't do is show what jdporter's solution has a problem. That would surely involve using jdporter's solution.

      where would preservation of %_ (jdporter mentioned $_) usually be of some importance?

      jdporter mentioned *_, not $_.

      And localizing %_ would be "of some importance" when %_ is changed, like in the parent of the post to which jdporter replied. The same applies to all global variables.

        ikegami:  I know it does exactly what you said it does

        Then I'll be glad to give some enlightment to you:
        sub uinq { @_ = do { @$_{@_}=(); keys %$_ }; @_ } my @array = (1,1,3,3,2,3,5,7,5,2); %_ = ( f=>'oo', b=>'ar' ); print "@{[ uinq @array ]}\n"; print map "\t$_ => $_{$_}\n", keys %_;

        ikegami:  jdporter mentioned *_, not $_.

        Better read back again then: http://perlmonks.org/?node_id=640777

        Regards & thanks
        mwa