How does this data structure work?

I need to debug an existing script without having much knowledge of perl.

This script uses data types like these to store all fields from a file:

${$LineRefs->{FIELD_NAME}}

I tried to figure out how to find all the possible fields separately, iterating over this scalar / hash / array, or whatever it is, but I don't know how to do it.

Can someone point me in the right direction?

+4
source share
1 answer

This is definitely very strange.

$LineRefsis a reference to a hash that has an element with a key FIELD_NAMEwhose value is a reference to a scalar

Like this

use v5.14;

my $LineRefs = {
    FIELD_NAME => \99,
};

print ${ $LineRefs->{FIELD_NAME} }, "\n";

Exit

99

, . ,



, @glennjackman , , -

, , scalar/hash/ , , ,

, , () ()

keys, values each,

, . $LineRefs -, %$LineRefs

for my $key ( keys %$LineRefs ) {
    my $value = $LineRefs->{$key};
    print "$key => $value\n";
}

, , SCALAR(0x640448)

+5

Source: https://habr.com/ru/post/1626876/


All Articles