in reply to Why does this happen?
As for the error message, let's look at:
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.$^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]!
-- Randal L. Schwartz, Perl hacker
|
---|
In Section
Seekers of Perl Wisdom