How can I use a Perl hash key with a literal dot?

I have a hash in Perl that has been unloaded from some inherited code, the key name has now changed from a simple reqHdrs to reqHdrs.bla

$rec->{reqHdrs.bla}

My problem is now I can’t access this field from the hash of any ideas? Below is my error

Download Script Output: Bareword "reqHdrs" not allowed while "strict subs" in use
+5
source share
5 answers

As described in perldoc perldata :

... , -. . $days{'Feb'} $days{Feb}, . - . , , $version{2.0}++ $version{2}++, $version{'2.0'}++.

, - [A-Za-z0-9_], ( ) . , , :

use strict; use warnings;
use Data::Dumper;
my $x = 1;
my %hash = (
    bare_string => 'hi there',
    "not a bare string" => 'yup',
);
$hash{'$x'} = 'foo';
$hash{"$x"} = 'bar';
print Dumper(\%hash);

:

$VAR1 = {
      'bare_string' => 'hi there',
      'not a bare string' => 'yup',
      '$x' => 'foo'
      '1' => 'bar',
    };
+17

perldoc perldata, , - , . , .

perldata

, , . . , $days{'Feb'} $days{Feb} . - . , , $version{2.0}++ $version{2}++, $version{'2.0'}++.

. , , , . , , , strict, , , " " ".

:

$rec->{'reqHdrs.bla'}
+5

, :

$rec->{"reqHdrs.bla"}
+4

:

$rec->{'reqHdrs.bla'}
+3

reqHdrs.bla ... , , . , , , . 'reqHdrs.bla' , OK.

-1

All Articles