index my $tring,$art
A variable declaration like my returns a value:
c:\@Work\Perl\monks>perl -wMstrict -le
"my $x = my $y = my $z = 42;
print $x;
"
42
In the case of your
index expression, the
my $tring sub-expression defines a scalar variable and default-initializes it with the (very well defined) undefined value
undef. This value is passed to the
index built-in and "promoted" to
'' (the empty string), but because you have wisely asked Perl to do so, Perl warns you about this rather suspicious transaction
(update: and also the business with my).
index then searches for an occurrence of the string in
$art within the empty string, and returns its success/failure. The string in
$art is never found, so
index always returns -1, which is a
true if-condition, and so everything gets printed.
Update: Here's an experiment: Is it possible that '' (the empty string) is a valid hash key? If so, if you add a new artist's name to your hash as the value of the key empty-string, will this artist's name be printed in the for-loop? In other words, can index identify the empty-string of the key within the empty-string of the promoted undef? If it can, what value will index return?
Give a man a fish: <%-(-(-(-<