in reply to Re^2: FATAL ERROR: Can't use string ("HASH(0x875fffc)") as a HASH ref while "strict refs" in use at
in thread FATAL ERROR: Can't use string ("HASH(0x875fffc)") as a HASH ref while "strict refs" in use at
It still works for me? Assuming that the relevant part of the program (going by the comments) is these 3 statements:
my %shared_data = ( 'dtLastRcvMsg' => time, 'dummy2' => 33, 'dummy' => 5 ); my ( $p1, $p2 ); # 1° test : OK $p1 = \%shared_data; $self->mylog( "P1: ($p1) " . Dumper( $p1 )); # 2° test : OK $p2 = $p1; $self->mylog( "P2: ($p2)" . Dumper( $p2 )); # 3° test : NOT-OK $self->{'shared_data'} = $p1; $p2 = $self->{'shared_data'}; $self->mylog( "P2: ($p2)" . Dumper( $p2 ));
This is the output I get from them:
c:\test\691728>..\junk.pl ..Non posso aprire il file /var/log/www/test1.dat (No such file or dir +ectory) print() on closed filehandle F at c:\test\junk.pl line 105. [2008.6.17 13:39:5] pid=2032 P1: (HASH(0x1e74f40)) $VAR1 = { 'dummy2' => 33, 'dummy' => 5, 'dtLastRcvMsg' => 1213706345 }; ..Non posso aprire il file /var/log/www/test1.dat (No such file or dir +ectory) print() on closed filehandle F at c:\test\junk.pl line 105. [2008.6.17 13:39:5] pid=2032 P2: (HASH(0x1e74f40))$VAR1 = { 'dummy2' => 33, 'dummy' => 5, 'dtLastRcvMsg' => 1213706345 }; ..Non posso aprire il file /var/log/www/test1.dat (No such file or dir +ectory) print() on closed filehandle F at c:\test\junk.pl line 105. [2008.6.17 13:39:5] pid=2032 P2: (HASH(0x1e74f40))$VAR1 = { 'dummy2' => 33, 'dummy' => 5, 'dtLastRcvMsg' => 1213706345 };
I had to disable a few things because I didn't have the relevant modules, but nothing that would affect those 3 outputs. For reference, here's the exact code I ran to get the above output:
#!/usr/bin/perl -w # package Test1; use strict; use warnings; use utf8; use CGI; # use HTTP::Lite; use HTTP::Request; use LWP::UserAgent; use XML::Simple; use XML::DOM; # use Tie::File::AsHash; use IO::Socket; use Sys::Hostname; # use IPC::Shareable; use Data::Dumper; my ( $fileTie ) = '/var/log/www/benzopmvutil.dat'; my ( $log_filename ) = '/var/log/www/test1.dat'; my %conf_data = ( 'test1' => 'abc' , 'test2' => '123'); my $test = Test1->new( \%conf_data ); # ================================================ # ================================================ sub new { my $that = shift; my $params = shift; my $class = ref($that) || $that; my $self = {}; bless($self, $class); # tie %$self, 'Tie::File::AsHash', $fileTie, split => '=' or die " +Problem tying %$self: $!"; $self->{counter} += 1; if( $self->{counter} > 9999 ) { $self->{counter} = 1; } $self->{last_call} = scalar localtime; my $s1 = Dumper( $self ); my %ipcshare_options = ( key => 'benz', create => 1, exclusive => 0, mode => 0666, destroy => 0, # size => IPC::Shareable::SHM_BUFSIZ() ); my %shared_data = ( 'dtLastRcvMsg' => time, 'dummy2' => 33, 'dummy' => 5 ); my ( $p1, $p2 ); # 1° test : OK $p1 = \%shared_data; $self->mylog( "P1: ($p1) " . Dumper( $p1 )); # 2° test : OK $p2 = $p1; $self->mylog( "P2: ($p2)" . Dumper( $p2 )); # 3° test : NOT-OK $self->{'shared_data'} = $p1; $p2 = $self->{'shared_data'}; $self->mylog( "P2: ($p2)" . Dumper( $p2 )); $p2->{'dtLastRcvMsg'} = time; # tie $self->{shared_data}, 'IPC::Shareable', { %ipcshare_options } + or tie %shared_data, 'IPC::Shareable', { %ipcshare_options } or die "[BenzoPmvUtil::init] shreable tie FAILED ( $ +! ) "; my $ppp = ( tied %shared_data ); # mylog( "TIED: ($!) " . Data::Dumper( \$ppp )); mylog( "SHMEM-ID: " . $ppp->{_shm}->{_id} ); #mylog( "IPC::Shareable::SHM_BUFSIZ: " . IPC::Shareable::SHM_BUFSI +Z() ); return $self; } # ============================================= sub mylog { my $self = shift; my( $strmsg ) = @_; my( $stmp, $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $i +sdst ); if( ! defined($log_filename)) { return }; ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = +localtime(time); $year += 1900; $mon += 1; open( F, ">>$log_filename" ) or open( F, ">$log_filename" ) or war +n "..Non posso aprire il file $log_filename ($!) \n"; print F "[$year.$mon.$mday $hour:$min:$sec] pid=$$ $strmsg) \n"; warn "[$year.$mon.$mday $hour:$min:$sec] pid=$$ $strmsg \n"; close F; }
I still suspect that you are simplifying the code for demonstration purposes and failing to demonstrate the problem.
Your not by any chance trying to share references between processes are you? Because that doesn't work!
|
|---|