http://www.perlmonks.org?node_id=1038003


in reply to Re^3: Dereference inside a regex
in thread Dereference inside a regex

I am using strict, warnings and diagnostics - always.
package MTA::Profile_ARM; use strict; use warnings; use diagnostics; use MTA::MapFileScientist; use vars qw($VERSION @ISA); $VERSION = 1.0; @ISA = qw(MTA::MapFileScientist); my $ProfileInformation = { 'StartLine' => 1, 'ObjAvailable' => 1, 'Compiler' => 'ARM', 'RAMMapping' => { 'RW Data' => 1, 'ZI Data' => 1, }, 'ROMMapping' => { 'Code' => 1, '(inc. data)' => 1, 'RO Data' => 1, } }; sub AnalyseMapFile { my $self = shift; my $MapFile = $self->{MAPFILEINFO}{MAPFILECONTENT}; my $PlaceToPutInformation = $self->{MEMORYMAP}; $self->{MAPFILEINFO}{ProfileInformation} = $ProfileInformation; my $memory_section = ''; my $state = 0; my $memory_size = 0; my $state_symbol = { 1 => 'Image component sizes', 2 => ' Code \(inc\. data\) RO Data RW Data ZI Dat +a Debug Object Name', }; #Each config profile defines its own way how to parse the map-file +. #Process map-file for ( my $iterator = $ProfileInformation->{'StartLine'} ; $iterator < @$MapFile ; $iterator++ ) { chomp($MapFile->[$iterator]); next if (! $MapFile->[$iterator]); if (( $state == 0 ) && ( $MapFile->[$iterator] =~m/$MTA::Profile_ARM::state_symbo +l->{'1'}/)) { ...
However, it is still not working..
as soon as I got the issue I will post here what has been
the root-cause.

Thanks a lot!

Cheers
Tobias

Update
I have changed the regex from $MTA::Profile_ARM::state_symbol->{'1'} to $state_symbol->{'1'} and its now working fine, without any shouting for not initialized values and stuff. This is because $state_symbol is a function-local scalar, so you cannot refer to it by giving the package-path. This has been the root-cause - quite simple.

Using strict was showing me at the beginning that I had a typo, it was telling me that $state_smybol was not defined. My mistake has been, that I have not got that its been a typo and extended the scalar by full path to package. Thus I got a different error and I have made things worse by not correctly reading the error msg - sorry for that !

:-)
Cheers!
Tobias