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

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.