[FR-EN] Pb de hachage dans un module (.pm) / make a hash in a module (.pm)

A

Alextophi

french version

bonjour,
je n'arrive pas à faire un hachage dans un module (.pm) avec des
données provenant d'un script (.pl).
Le problème vient du fait que le hachage est désorganisé et contient
le nom du module dans le hachage ! je ne comprends pas comment il est
là.

d'avance merci

Alextophi

#############################################################################
english version

hello,
I do not manage to make a hash in a module (pm) with data coming from a
script (pl). The problem comes owing to the fact that hash is
disorganized and contains the name of the module in hash ! I do not
include/understand how it is there.

in advance thank you
Alextophi

#############################################################################
- SCRIPT (test.pl),

$req1 = Import_contrainte->ajout_contrainte2(
'nom' => "Paul",
'id' => "008",
'col' => "g2"
);


- MODULE (Import_comtrainte.pm),

sub ajout_contrainte2 {

my %hash = (@_);
my ($cle, $valeur);

foreach $cle (sort(keys %hash)) {
print $cle, '=', $hash{$cle}, "\n";
}

} # fin de fonction


- Result,

008=col
Import_contrainte=nom
Paul=id
g2=

!?!?!?!?!?!?!?!?!
 
R

Reinhard Pagitsch

Hello Alextophi,
french version

bonjour,
je n'arrive pas à faire un hachage dans un module (.pm) avec des
données provenant d'un script (.pl).
Le problème vient du fait que le hachage est désorganisé et contient
le nom du module dans le hachage ! je ne comprends pas comment il est
là.

d'avance merci

Alextophi

#############################################################################
english version

hello,
I do not manage to make a hash in a module (pm) with data coming from a
script (pl). The problem comes owing to the fact that hash is
disorganized and contains the name of the module in hash ! I do not
include/understand how it is there.

in advance thank you
Alextophi

#############################################################################
- SCRIPT (test.pl),

$req1 = Import_contrainte->ajout_contrainte2(
'nom' => "Paul",
'id' => "008",
'col' => "g2"
);


- MODULE (Import_comtrainte.pm),

sub ajout_contrainte2 {

my %hash = (@_);
my ($cle, $valeur);

foreach $cle (sort(keys %hash)) {
print $cle, '=', $hash{$cle}, "\n";
}

} # fin de fonction


- Result,

008=col
Import_contrainte=nom
Paul=id
g2=

!?!?!?!?!?!?!?!?!

Try this:
--------- .pl ------------------
my $inst = Hello->new();
$inst->PassHash(
'nom' => "Paul",
'id' => "008",
'col' => "g2"
);

-------------.pm -------------------
sub new
{
my $class = shift;
my $h;
my $self = {
AFPDS=>undef ,
CodePage=>undef,
resources=>[],
isError=>0,
HANDLE=>undef,
Error=>undef
};
bless $self, $class;
return $self;

}

sub PassHash
{
my $self = shift;
my %h = @_;
my $cle;
foreach $cle (sort(keys %h)) {
print $cle, '=', $h{$cle}, "\n";
}
}

You do not pass the package name ($self) to the sub in the .pm:
Import_contrainte->ajout_contrainte2(..)
In your case use :
ajout_contrainte2(
'nom' => "Paul",
'id' => "008",
'col' => "g2"
);


regards,
Reinhard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top