Same mistake: my %hGui = {};. Again, that's mistakenly assigning a hashref to an actual hash. It's a juxtaposition of data types. A %hash expects a list. A {} returns a reference, not a list. That's where you're getting the warning you asked about.

Also, $gGui{source} = ( my $source, "" ) is another problem. $gGui{source} expects a scalar value, not a list. You're trying to provide it with a list. The first element of the list would be undef, because it is the return value from my $source, which since $source isn't asigned a value, is an undefined value. The second element of the list is "" (an empty string). But since $gGui{source} provides scalar context to the expression, there's no list; just the rightmost element in what would have been a list; the empty string, "". Confusing? Yes, but it doesn't have to be.

The specifics of the comma operator in scalar context are discussed in perlop. But you're missing the bigger picture here somehow.

Hashes (the datatype) hold a list of scalars, indexed by hash keys. If you assign a list of two elements to a hash, the first element will be taken as a hash key, and the second as a hash value. Ten elements will be five keys and five values. An odd number of elements will throw a warning.

Hash elements accept scalar values. Scalar values can be a lot of things such as numbers, strings, undef, or references to other scalars, hashes, arrays, or whatever.

Please do read through perlintro. Follow that by perldata, and then follow up with perlref, perlreftut, and perllol. We're talking about a few hours of reading here, but you'll find yourself greatly enlightened on some concepts that may seem a little complicated at first.


Dave


In reply to Re^3: Hash/Associative Array by davido
in thread Hash/Associative Array by Real Perl

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.