Perl is trying to interpret bob as an array reference and bombing out with a slightly confusing error message.
I must disagree, I don't think it is confusing, once you understand what's going on.

Perl has a feature to use symbolic references, i.e. a variable may contain the name of a global variable and you can access its contents through it. For example:

our $red = 10; our $green = 6; my $apples = 'red'; $$apples--; # eat an apple print "I've got $red red apples, and $green green ones.\n";
Result:
I've got 9 red apples, and 6 green ones.

It's a powerful system but abusing it is not a good idea. That's why strict prevents it by default (when you use strict;).

What is the source of the confusion here, is that the syntax (and the code for the internals) is the same as with real references instead of strings.

It also works with hashes and arrays for data, and with any kind of scalar as the symbolic reference. And that is what is going on here: $hash{a} contains the string 'bob' so $hash{a}[0] is trying to either use $hash{a} as an array reference (if it is a reference; or undef, which is what we usually want anyway) or, since it is a string here, as a symbolic reference to the global variable @bob. And the latter is what strict is preventing, with that error message as a result

Try it with no strict:

our @bob; my %hash; $hash{a} = 'bob'; $hash{a}[0] = 1; print "\@bob contains: [@bob]\n";
which results in
@bob contains: [1]

In reply to Re^2: Extending a hash by bart
in thread Extending a hash by dingbob

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.