#!/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 "P
+roblem 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;
}
=======================================
The output is the one below
[enzo@P0101222 benzopmv]$ ./Test1.pm
[2008.6.17 13:49:32] pid=27534 P1: (HASH(0x8755f48)) $VAR1 = {
'dummy2' => 33,
'dummy' => 5,
'dtLastRcvMsg' => 1213703372
};
[2008.6.17 13:49:32] pid=27534 P2: (HASH(0x8755f48))$VAR1 = {
'dummy2' => 33,
'dummy' => 5,
'dtLastRcvMsg' => 1213703372
};
[2008.6.17 13:49:32] pid=27534 P2: (HASH(0x8755f48))$VAR1 = 'HASH(0x87
+55f48)';
Can't use string ("HASH(0x8755f48)") as a HASH ref while "strict refs"
+ in use at ./Test1.pm line 85, <$fh> line 95.
As you can see , it seem that when I assign the hash reference to an element of another hash I then I read it back, it's value it's corrupted.
BTW : my revision of perl is the 5.6.1 and I run it on red-hat 7.3 and slackware 8
Belowe the full status of my perl installation, my be it should be usefull
[enzo@P0101222 cgi-bin]$ perl -V
Summary of my perl5 (revision 5.0 version 6 subversion 1) configuratio
+n:
Platform:
osname=linux, osvers=2.4.21-1.1931.2.393.entsmp, archname=i386-lin
+ux
uname='linux bugs.devel.redhat.com 2.4.21-1.1931.2.393.entsmp #1 s
+mp thu aug 14 14:47:21 edt 2003 i686 unknown '
config_args='-des -Doptimize=-O2 -march=i386 -mcpu=i686 -Dcc=gcc -
+Dcf_by=Red Hat, Inc. -Dcccdlflags=-fPIC -Dinstallprefix=/usr -Dprefix
+=/usr -Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Uu
+sethreads -Uuseithreads -Uuselargefiles -Dd_dosuid -Dd_semctl_semun -
+Di_db -Di_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Dinc_ver
+sion_list=5.6.0/i386-linux 5.6.0'
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef usemultipl
+icity=undef
useperlio=undef d_sfio=undef uselargefiles=undef usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
Compiler:
cc='gcc', ccflags ='-fno-strict-aliasing -I/usr/local/include',
optimize='-O2 -march=i386 -mcpu=i686',
cppflags='-fno-strict-aliasing -I/usr/local/include'
ccversion='', gccversion='2.96 20000731 (Red Hat Linux 7.3 2.96-11
+3)', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=1
+2
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
+ lseeksize=4
alignbytes=4, usemymalloc=n, prototype=define
Linker and Libraries:
ld='gcc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -ldl -lm -lc -lcrypt -lutil
perllibs=-lnsl -ldl -lm -lc -lcrypt -lutil
libc=/lib/libc-2.2.5.so, so=so, useshrplib=false, libperl=libperl.
+a
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynami
+c'
cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'
Characteristics of this binary (from libperl):
Compile-time options:
Built under linux
Compiled at Aug 18 2003 16:08:31
@INC:
/usr/lib/perl5/5.6.1/i386-linux
/usr/lib/perl5/5.6.1
/usr/lib/perl5/site_perl/5.6.1/i386-linux
/usr/lib/perl5/site_perl/5.6.1
/usr/lib/perl5/site_perl/5.6.0
/usr/lib/perl5/site_perl
/usr/lib/perl5/vendor_perl/5.6.1/i386-linux
/usr/lib/perl5/vendor_perl/5.6.1
/usr/lib/perl5/vendor_perl
|