Storing array as map values problem

Question!

I want @arr to directly contain the cities name. I want $arr[0] to be c1 when I print. What is wrong with the code?

my $state="Illinois";

 push @{$mstates{$state}}, "c1";

 push @{$mstates{$state}}, "c2";


 my @arr=$mstates{$state};
By : user5858


Answers

Do it like,

my @[email protected]{$mstates{$state}}; 

ie.,

use strict;
use warnings;
use Data::Dumper;
my $state="Illinois";
my %mstates;
 push @{$mstates{$state}}, "c1";
 push @{$mstates{$state}}, "c2";
 my @[email protected]{$mstates{$state}};
 print Dumper(\@arr);

output:

$VAR1 = [
          'c1',
          'c2'
        ];


maybe you wanted

my @[email protected]{$mstates{$state}};
By : rmflow


This video can help you solving your question :)
By: admin