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 )); #### c:\test\691728>..\junk.pl ..Non posso aprire il file /var/log/www/test1.dat (No such file or directory) 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 directory) 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 directory) 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 }; #### #!/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_BUFSIZ() ); return $self; } # ============================================= sub mylog { my $self = shift; my( $strmsg ) = @_; my( $stmp, $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ); 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 warn "..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; }