------=_NextPart_000_009F_01C4735B.B26072E0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Hi!
I do not know I am on the right mailing list.
If not, sorry for the burden.
To say thing briefly:
I am a programmer for some 25 years using various old and newer languages.
I have to write some small things in Perl.
It was fine and fast with some text analysis.
Now I have to write something using an in-memory "database", i.e. a SINGLE
table filled with records.
I am trying to simply add records then retriev them.
I already spent more than 20 hours for something which should take 30
minutes....
Seriousely considering making my customer change his mind and revert to
plain old C++
Just to be certain not to miss something simple, I attach a small part of
my
very, very basic trials.
As you can see when running this small piece of "code", as soon as you
push
a new record, all records already existing become
filled with the new pushed record and it is impossible to get any other...
Looks like Perl is not able to handle trivial data structure like an array
of records (or hashes).
Thank you for any help!
Caracal - G. Hostettler
6, ch. du Raidillon
1522 Lucens
------=_NextPart_000_009F_01C4735B.B26072E0
Content-Type: application/octet-stream;
name="hashbad.pl"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="hashbad.pl"
#!/usr/bin/perl -w=0A=
#=0A=
=0A=
# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
# Declaration of subs=0A=
# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
=0A=
# Adds a record to the end of the "table" and returns a recID=0A=
# Returns false (undef) if fails, else returns true (1).=0A=
sub addrec(%); # parm 1 if the rec hash=0A=
=0A=
# Deletes rec designated by parm 1. If the recnr is out=0A=
# of the table scope (<0 or >$TBLSIZE) it fails and returns=0A=
# false (or undef), else it returns 1.=0A=
sub delrec($ \%); # parm 1 if the rec nr, parm 2 is the rec data=0A=
=0A=
# Gets rec designated by parm 1 and returns it=0A=
sub getrec($); # parm 1 if the rec nr, parm 2 is the rec data=0A=
=0A=
# Puts (writes) the record % at pos $. If $ > $TBLSIZE it=0A=
# adds it @[EMAIL PROTECTED]
the end of the table, like addrec.=0A=
sub putrec($ \%); # parm 1 if the rec nr, parm 2 is the rec data=0A=
=0A=
#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
# Some GLOBALS - never a perfect world...=0A=
#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
=0A=
# This our "table and "record" with initial values=0A=
# As this plain shit "language" called perl is unable=0A=
# to handle arrays of records simply, we have to declare=0A=
# the whole structure at once.=0A=
@[EMAIL PROTECTED]
=3D (=0A=
{PPID =3D> 0, =0A=
SID =3D> 0, =0A=
FRQ =3D> 0, =0A=
TIMEWIN =3D> "00:00:00", =0A=
PRIO =3D> 4, =0A=
WEIGHT =3D> 1}=0A=
);=0A=
=0A=
#=0A=
#-------------------------------------------=0A=
# PROCEDURE : addrec(%)=0A=
# CALLED FROM : anywhere=0A=
# PURPOSE : Adds a record at the end of %table and updates=0A=
# $TBLSIZE. Returns true if sucessfull or false=0A=
# otherwise.=0A=
# PREREQUISITES : perl and needed libraries.=0A=
# PARAMETERS : % is the table structure as defined under "Globals"=0A=
# section.=0A=
# REMARKS : This is a DUMB general-purpose sub!=0A=
# It does NOT check if the pair PPID-SID already
exists=0A=
# and/or if the WEIGHT field is already defined.=0A=
# This is the purpose of smarter subs, like getweight($ =
$).=0A=
=0A=
sub addrec(%)=0A=
{=0A=
my %lrec =3D @[EMAIL PROTECTED]
push @[EMAIL PROTECTED]
[ %lrec ];=0A=
my $lrec=3D$table[$#table -1];=0A=
print("Got rec: $lrec{PPID}-$lrec{SID}\n");=0A=
#%lrec =3D (PPID =3D> $lrec{PPID},=0A=
# SID =3D> $lrec{SID},=0A=
# FRQ =3D> $lrec{FRQ},=0A=
# TIMEWIN =3D> $lrec{TIMEWIN},=0A=
# PRIO =3D> $lrec{PRIO},=0A=
# WEIGHT =3D> $lrec{WEIGHT});=0A=
#print 'Table size is now: ', $#table, "\n";=0A=
#my @[EMAIL PROTECTED]
=3D keys %lrec;=0A=
#my @[EMAIL PROTECTED]
=3D values %lrec;=0A=
#while (@[EMAIL PROTECTED]
) {=0A=
# print pop(@[EMAIL PROTECTED]
), '=3D' , pop(@[EMAIL PROTECTED]
), "\n";=0A=
#}=0A=
=0A=
}=0A=
=0A=
#=0A=
#-------------------------------------------=0A=
# PROCEDURE : getrec($)=0A=
# CALLED FROM : anywhere=0A=
# PURPOSE : Returns the record pointed to by $_[0].=0A=
# if the parm is <0 or >$TBLSIZE=0A=
# returns undef, else the hash holding=0A=
# the data.=0A=
# PREREQUISITES : perl and needed libraries.=0A=
# PARAMETERS : $ is the record #.=0A=
# REMARKS : This is self-containing ans self error-reporting
sub.=0A=
# Say smarter than addrec.=0A=
=0A=
sub getrec($)=0A=
{=0A=
my $recnum =3D $_[0];=0A=
my %lrec =3D ( );=0A=
print ("Trying to get record: $recnum\n");=0A=
=0A=
if (($recnum < 0) or ($recnum > ($#table -1) )) {=0A=
print ("Returning: UNDEF\n");=0A=
return undef=0A=
} else {=0A=
my $lrec =3D $table[$recnum];=0A=
%lrec =3D (PPID =3D> $lrec{PPID},=0A=
SID =3D> $lrec{SID},=0A=
FRQ =3D> $lrec{FRQ},=0A=
TIMEWIN =3D> $lrec{TIMEWIN},=0A=
PRIO =3D> $lrec{PRIO},=0A=
WEIGHT =3D> $lrec{WEIGHT});=0A=
#print ("Returning: $lrec{PPID}-$lrec{SID}\n");=0A=
return %lrec;=0A=
}=0A=
=0A=
}=0A=
##############################=0A=
# MAIN=0A=
##############################=0A=
=0A=
# OK, we try to test=0A=
my %testrec =3D (PPID =3D> 1,=0A=
SID =3D> 450,=0A=
FRQ =3D> 20,=0A=
TIMEWIN =3D> "12:04:35",=0A=
PRIO =3D> 2,=0A=
WEIGHT =3D> 1);=0A=
addrec %testrec;=0A=
print "Added rec. tblsize =3D $#table\n";=0A=
=0A=
%testrec =3D (PPID =3D> 1,=0A=
SID =3D> 510,=0A=
FRQ =3D> 20,=0A=
TIMEWIN =3D> "12:04:35",=0A=
PRIO =3D> 2,=0A=
WEIGHT =3D> 1);=0A=
addrec %testrec;=0A=
print "Added rec. tblsize =3D $#table\n";=0A=
=0A=
my $testrec =3D getrec(0);=0A=
%testrec =3D (PPID =3D> $testrec{PPID},=0A=
SID =3D> $testrec{SID},=0A=
FRQ =3D> $testrec{FRQ},=0A=
TIMEWIN =3D> $testrec{TIMEWIN},=0A=
PRIO =3D> $testrec{PRIO},=0A=
WEIGHT =3D> $testrec{WEIGHT});=0A=
print "Record 0\n";=0A=
my @[EMAIL PROTECTED]
=3D keys %testrec;=0A=
my @[EMAIL PROTECTED]
=3D values %testrec;=0A=
while (@[EMAIL PROTECTED]
) {=0A=
print pop(@[EMAIL PROTECTED]
), '=3D' , pop(@[EMAIL PROTECTED]
), "\n";=0A=
}=0A=
=0A=
$testrec =3D getrec(1);=0A=
%testrec =3D (PPID =3D> $testrec{PPID},=0A=
SID =3D> $testrec{SID},=0A=
FRQ =3D> $testrec{FRQ},=0A=
TIMEWIN =3D> $testrec{TIMEWIN},=0A=
PRIO =3D> $testrec{PRIO},=0A=
WEIGHT =3D> $testrec{WEIGHT});=0A=
print "\nRecord 1\n";=0A=
@[EMAIL PROTECTED]
=3D keys %testrec;=0A=
@[EMAIL PROTECTED]
=3D values %testrec;=0A=
while (@[EMAIL PROTECTED]
) {=0A=
print pop(@[EMAIL PROTECTED]
), '=3D' , pop(@[EMAIL PROTECTED]
), "\n";=0A=
}=0A=
###############################=0A=
# END OF caidssuspicious.pl=0A=
###############################=0A=
------=_NextPart_000_009F_01C4735B.B26072E0--


|