I have a hash in Perl which has been dumped into from some legacy code the name of the key has now changed from simply reqHdrs to reqHdrs.bla
$rec->{reqHdrs.bla}
My problem is now I cant seem to access this field from the hash any ideas? The following is my error
Download Script Output: Bareword "reqHdrs" not allowed while "strict subs" in use
If the key is a string, just:
As described in perldoc perldata:
In general, if you have a hash key with a character outside the
[A-Za-z0-9_]
range, use quotes (either single or double) inside the braces. As with normal strings, contents in double quotes will be parsed for any contained variables, while single quoted strings are taken literally:prints:
According to
perldoc perldata
that when an identifier is used within curlies, such as when accessing a hash value via a key, that identifier is assumed to be a string and is treated as such. Quotes will be assumed automatically, however, anything more complicated can be interpreted.From perldata
Since the
.
is used for string concatenation, the interpreter I'm guessing is trying to concat those two strings together. Regardless it's always better to just use quotes to make it explicit, and if you have strict on it will probably throw a "bareword not allowed" error.The solution to your problem:
Enclose the key in quotes:
The bareword
reqHdrs.bla
is really just a... synonym, I guess, for a string. I'm not completely sure, but I think you should be able to simply use a string, e.g.'reqHdrs.bla'
as your key and that should retrieve your value OK.