As for the error message, let's look at:
$^W = 1;
$index = 0..2; # this is your problem - it's initially undef
@matching = qw(disk duck deck);
$result = $matching[$index]; # and here's your problem, $matching[unde
+f]!
You've done the
.. operator in a scalar context, making it the flip-flop range
operator, but you've not read any input, so you're not at line 0 yet, so the
value is undef (outside the range so far). This value will be true only when
$. is between 0 and 2, inclusively.
-- Randal L. Schwartz, Perl hacker