in reply to Re: syntax for hashes with variable in name
in thread syntax for hashes with variable in name

Your immediate problem is that perl interprets your %{ as a hash slice

Is this for real?

  • Comment on Re^2: syntax for hashes with variable in name

Replies are listed 'Best First'.
Re^3: syntax for hashes with variable in name
by Tux (Canon) on Nov 22, 2010 at 16:46 UTC

    is it?

    Let's rule out the fact that this deals with symbolic references, strict tells us ...

    use strict; use warnings; { no strict "refs"; my $site = "foo"; my @{"platforms_$site"} = qw( foo bar ); my %{"platforms_$site"} = map { $_ => 1 } @{"platforms_$site"}; } => Can't declare array dereference in "my" at xx.pl line 8, near "} =" Execution of xx.pl aborted due to compilation errors.

    The difference is in the assignment part. You cannot use my there. When you drop those, you get:

    use strict; use warnings; { no strict "refs"; my $site = "foo"; @{"platforms_$site"} = qw( foo bar ); %{"platforms_$site"} = map { $_ => 1 } @{"platforms_$site"}; }

    Which is still bad coding style, but this works.


    Enjoy, Have FUN! H.Merijn
Re^3: syntax for hashes with variable in name
by jethro (Monsignor) on Nov 22, 2010 at 16:02 UTC

    It was the best explanation I could find at the moment. But I didn't check with deparse or something.