in reply to 1 line array to hash converter

Almost!
@hash{@array} = (1) x scalar(@array};
need to put an @ at the front... not sure why, but you do

                - Ant
                - Some of my best work - Fish Dinner

Replies are listed 'Best First'.
(jeffa) 2Re: 1 line array to hash converter
by jeffa (Bishop) on Sep 21, 2001 at 18:54 UTC
    The @ sign pretty much tells the interpreter to expect a SLICE, and since hash is (hopefully) already defined as a hash, you get a hash slice. :)

    japhy has a great little 'tutorial' i found (via google) at http://www.crusoe.net/~jeffp/docs/using_refs

    jeffa

      Actually, it's the type of brackets - {} - that tells Perl that's it's a hash slice.

      --
      <http://www.dave.org.uk>

      "The first rule of Perl club is you don't talk about Perl club."

        Just because your statement confused me a little:

        The type of brackets - {} - tells Perl that it's a hash.
        The @ tells Perl to use list context vs. scalar context.

        Note the difference between:

        @hash{@array} = (1) x scalar(@array); print join(" -- ", keys %hash), "\n"; #AND $hash{@array} = (1) x scalar(@array); print join(" -- ", keys %hash), "\n";
Re: Re: 1 line array to hash converter
by clintp (Curate) on Sep 21, 2001 at 20:54 UTC
    Nit: useless use of scalar
    @hash{@array}=(1) x @array;
    Works peachy as well.