in reply to Re: Better way to search?
in thread Better way to search?

@exts{@exts} = ();
what does that do?

Replies are listed 'Best First'.
Re: Re: Re: Better way to search?
by btrott (Parson) on Jan 05, 2001 at 06:17 UTC
    It's a hash slice.

    It fills the hash %exts with the contents of your @exts array. The keys are set to the values in @exts, and the values in the hash are set to undef. That's why you need to test for exists rather than "truth"; because the values aren't "true", but the keys do exist.

      Ah, I see. So if I have this:
      @exts = {'jpg','jpeg','gif'); %exts; @exts{@exts} = ();
      then we get an %exts array that is the same as this:
      %exts = ('jpg'=>'','jpeg'=>'','gif'=>'');
      Right? Why do you so @exts{@exts} and not %exts{@exts}?
        Right? Why do you so @exts{@exts} and not %exts{@exts}?
        Because one's legal and the other isn't!

        A slice acts as an array. So therefore, the starting symbol is "at", meaning "array".

        -- Randal L. Schwartz, Perl hacker

        Regarding the first question: not quite, s/''/undef/g, and then they're the same.