in reply to Set::Scalar saves you from hash acrobatics

One comment on the first syntax... I've always preferred to populate hashes like so in those situations.
my %stopwords = map { $_ => 1 } qw(a i at be do to or is not no the that they then these them who where why can find on an of and it by );


-Lee

"To be civilized is to deny one's nature."

Replies are listed 'Best First'.
Re: Re: Set::Scalar saves you from hash acrobatics
by Ovid (Cardinal) on Oct 06, 2003 at 19:00 UTC

    Not to mention the fact that the original code has a bug. There needs to be parentheses around the "1" to force list context.

    #!/usr/bin/perl use strict; use Data::Dumper; my (%hash1, %hash2); my @keys = qw/foo bar baz/; @hash1{@keys} = 1 x 3; @hash2{@keys} = (1) x 3; print Dumper \%hash1, \%hash2;

    That generates:

    $VAR1 = {
              'foo' => '111',
              'baz' => undef,
              'bar' => undef
            };
    $VAR2 = {
              'foo' => 1,
              'baz' => 1,
              'bar' => 1
            };

    Cheers,
    Ovid

    New address of my CGI Course.