in reply to Re^2: keys of hash
in thread keys of hash

Yes, it is possible:
my %hash; @hash{@array} = ();
This will make your list unique since a hash cannot have duplicate keys.

Replies are listed 'Best First'.
Re^4: keys of hash
by prafull (Novice) on May 18, 2010 at 11:01 UTC
    Thanx , it worked .....
    I have one more problem.
    @array = (10,29,30,19,48,45,89,14,99,41);

    my %hash;
    @hash{@array} = ();

    use Data::Dumper::Simple;
    print Dumper(%hash);


    Output of this is

    %hash = (
    '41' => undef,
    '14' => undef,
    '48' => undef,
    '99' => undef,
    '30' => undef,
    '45' => undef,
    '89' => undef,
    '10' => undef,
    '19' => undef,
    '29' => undef
    );

    here , i want to keep 1 as value of each key instead of undef.

    I tried this ...
    @hash{@array} = ();

    but i got o/p as follows ,

    %hash = (
    '41' => undef,
    '14' => undef,
    '48' => undef,
    '99' => undef,
    '30' => undef,
    '45' => undef,
    '89' => undef,
    '10' => 1,
    '19' => undef,
    '29' => undef
    );


    Regards,
    Prafull
      Try
      @hash{@array} = map 1,@a;
      It will map 1 to each member of the array.

        Using @hash{ @array } = (1) x @array would be more idiomatic. There's no need to get map involved since you really aren't changing the values of the array at all.

        The cake is a lie.
        The cake is a lie.
        The cake is a lie.

        worked .. thanx a lot