I have a Perl script that has (skipping many irrelevant lines)
use HTML::Entities;
my @keys = ('ID', 'first', 'last'); # data is not actually constant
my @encodedKeys = map(encode_entities, @keys);
which runs without error. But when I try to access the values in the array, I get errors:
Use of uninitialized value $encodedKeys[0] in join or string at myfile.pl line 48.
If I remove the mapping the code works properly — that is, the variables are not null or empty strings. What am I doing wrong? Is there a good idiomatic way to do this? (It’s obviously trivial to do sequentially.)
For the code to work correctly as posted in the question,
encode_entitiesneeds to be prototyped. A quick glance at the source code shows that this isn’t the case.The correct way to call it is: