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

Of course, that clobbers $_. Perhaps you want to insert

local *_;
at the beginning of that do block.

Replies are listed 'Best First'.
Re^3: Remove redundency from an array
by mwah (Hermit) on Sep 24, 2007 at 19:16 UTC
    jdporter: Of course, that clobbers $_. Perhaps you want to insert local *_; ...

    Would this (*_) be relevant here?

    $_ *might* be localized, but *_ imho not.

    consider:
    sub uinq { # local *_; # <== will fail, $_ will work @_ = do { @$_{@_}=(); keys %$_ }; @_ } my @array = (1,1,3,3,2,3,5,7,5,2); print "@{[ uinq @array ]}\n";


    Regards & thanks
    mwa

      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 %_.

        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

      Good point. It's up to you (the programmer) to protect/preserve the contents of @_ if necessary. It wasn't necessary in the code you gave.

      ikegami may be too modest to point out his previous discursion on the subject.