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

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

  • Comment on Re: Re: Re: Re: Re: Better way to search?

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Better way to search?
by tilly (Archbishop) on Jan 05, 2001 at 06:38 UTC
    Slices don't act like arrays in scalar context though.

    That has always bugged me. Personally I wish that Perl were a little less DWIM about:

    $elem = @array[0];
    If that did something completely unexpected to the novice, then they might learn sooner what the correct notation is...
        I know what they do. I just think it would be better if they did something else. :-)
Re: Re: Re: Re: Re: Re: Better way to search?
by r.joseph (Hermit) on Jan 05, 2001 at 06:38 UTC
    Sorry to keep bugging y'all, but this is really helpful and interesting. So if I did something like this:
    @exts{@exts} = @exts;
    would that make both the keys AND the values equal (and obviously, the values of the @exts array)?
      Yes. See:
      my @exts = qw/foo bar baz/; my %exts; @exts{@exts} = @exts; use Data::Dumper; print Dumper \%exts;
      produces:
      $VAR1 = { 'foo' => 'foo', 'baz' => 'baz', 'bar' => 'bar' };
      I might point out that nothing answers a question so well as testing a bit of code out yourself. :)