Your code gives me the error
Odd number of elements in hash assignment at ./t4.pl line 6.
Hashes are defined this way:
my %hash = ( somekey => somevalue, ...);
So your code should read:
#!/usr/bin/perl -w use strict; use Data::Dumper; my %w = ( Sub => { 'rbscells' => 'UtranCell=RNC16-4-1', 'UtranCell=RNC16-4-2', 'UtranCell=RNC16-4-3' } ) ; print Dumper(%w);
Now when you look at the output of Data::Dumper, you can see, that what you probably wanted to be an array (the three strings starting with "UtranCell*") are in fact a hash value and another hash key + value:
$VAR1 = 'Sub'; $VAR2 = { 'rbscells' => 'UtranCell=RNC16-4-1', 'UtranCell=RNC16-4-2' => 'UtranCell=RNC16-4-3' };
However, you can't just put an array definition inside a hash - from perldsc:
The most important thing to understand about all data structures in Perl--including multidimensional arrays--is that even though they might appear otherwise, Perl @ARRAYs and %HASHes are all internally one-dimensional. They can hold only scalar values (meaning a string, number, or a reference). They cannot directly contain other arrays or hashes, but instead contain references to other arrays or hashes.
So another change, to define an array reference:
... 'rbscells' => [ 'UtranCell=RNC16-4-1', 'UtranCell=RNC16-4-2', 'UtranCell=RNC16-4-3' , ] ...
You can access the elements of the array as always, via index starting from 0 or with foreach like this:
foreach my $element (@{$w{Sub}->{rbscells}}) { print $element . "\n"; }
To understand nested data structures in perl, please refer to perldsc, especially the chapter about "Hashes of Arrays".

In reply to Re: Usage of hashes with hashes when mulitple values are present by lune
in thread Usage of hashes with hashes when mulitple values are present by Bhagya

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.