great and better hash eval

J

john swilting

I do not understand .i start the deboguor ,is the file test.dat is well
execute.in the file main.pl the loop while does not seem to function
correctly. one only value is returned to me before keys. it appears
infinite
##########################################################################
#main.pl
##########################################################################
#!/usr/bin/perl

require "ouvre_fichier.pl";
$f = "test.dat";
%fh = ouvre_fichier($f);;
while(( $clef,$valeur) = each %fh){
print $clef;
keys %fh;
}
########################################################################
#ouvre_fichier.pl
########################################################################
!/usr/bin/perl
sub ouvre_fichier {
open ($F, $_[0]) || die "impossible d ouvrir le fichier : $!";
while($ligne =<$F>){
$str.= $ligne;
}
eval $str;
}
$f = 'test.dat';
while(1){
eval {
ouvre_fichier($f);#si ouvre fichier echoue, le programme ne se termine pas
};##et à mon avis c la dernier veleur utliser
last unless $@; #pas d erreur on sort de la boucle
print "$f est absent. entrez un nouveau nom de fichier $f";
chomp ($f = <STDIN>);
}

1
#######################################################################
#test.dat
#######################################################################
$Conf{XferMethod} = 'rsync';
$Conf{XferLogLevel} = '1';
$Conf{RSyncShareName} = '___1___';
$Conf{ClientNameAlias} = '___2___';
 
A

anno4000

john swilting said:
I do not understand .i start the deboguor ,is the file test.dat is well
execute.in the file main.pl the loop while does not seem to function
correctly. one only value is returned to me before keys. it appears
infinite
##########################################################################
#main.pl
##########################################################################
#!/usr/bin/perl

require "ouvre_fichier.pl";
$f = "test.dat";
%fh = ouvre_fichier($f);;
while(( $clef,$valeur) = each %fh){
print $clef;
keys %fh;

What is the call to "keys %fh" for? It does nothing useful but messes
up the iteration.

The call to "keys %fh" resets the iterator that controls the behavior
of "each". Instead of giving you the next key/value pair it gives you
the first one again. That leads to the endless loop you're observing.
Remove the line, then the loop will work as expected.
########################################################################
#ouvre_fichier.pl
########################################################################
!/usr/bin/perl
sub ouvre_fichier {
open ($F, $_[0]) || die "impossible d ouvrir le fichier : $!";
while($ligne =<$F>){
$str.= $ligne;
}
eval $str;
}
$f = 'test.dat';
while(1){
eval {
ouvre_fichier($f);#si ouvre fichier echoue, le programme ne se termine pas
};##et à mon avis c la dernier veleur utliser
last unless $@; #pas d erreur on sort de la boucle
print "$f est absent. entrez un nouveau nom de fichier $f";
chomp ($f = <STDIN>);
}

1
#######################################################################
#test.dat
#######################################################################
$Conf{XferMethod} = 'rsync';
$Conf{XferLogLevel} = '1';
$Conf{RSyncShareName} = '___1___';
$Conf{ClientNameAlias} = '___2___';

From your usage the function ouvre_fichie() is supposed to set up
a hash. As far as I can see without running it, it returns the
single value "___2___", in an incredibly convoluted manner.

Anno
 
J

john swilting

#update code
print "$clef => $valeur";
# keys %fh;
#assuming not infinite loop
What is the call to "keys %fh" for? It does nothing useful but messes
up the iteration.

The call to "keys %fh" resets the iterator that controls the behavior
of "each". Instead of giving you the next key/value pair it gives you
the first one again. That leads to the endless loop you're observing.
Remove the line, then the loop will work as expected.
########################################################################
#ouvre_fichier.pl
########################################################################
!/usr/bin/perl
sub ouvre_fichier {
open ($F, $_[0]) || die "impossible d ouvrir le fichier : $!";
while($ligne =<$F>){
$str.= $ligne;
}
eval $str;
}
$f = 'test.dat';
while(1){
eval {
ouvre_fichier($f);#si ouvre fichier echoue, le programme ne se termine
pas };##et à mon avis c la dernier veleur utliser
last unless $@; #pas d erreur on sort de la boucle
print "$f est absent. entrez un nouveau nom de fichier $f";
chomp ($f = <STDIN>);
}

1
#######################################################################
#test.dat
#######################################################################
$Conf{XferMethod} = 'rsync';
$Conf{XferLogLevel} = '1';
$Conf{RSyncShareName} = '___1___';
$Conf{ClientNameAlias} = '___2___';

From your usage the function ouvre_fichie() is supposed to set up
a hash. As far as I can see without running it, it returns the
single value "___2___", in an incredibly convoluted manner.

Anno
I do not understand .ok any more while infinite. now only a key is turned
over, ___ 2___. at the time of eval of test.dat the last value used it is
my hash I think?. ouvre_fichier should return the hach in entirety
Perl main.pl
___ 2 ___ =>

it is the key or is the value ?
 
A

anno4000

john swilting said:
#update code
print "$clef => $valeur";
# keys %fh;
#assuming not infinite loop
What is the call to "keys %fh" for? It does nothing useful but messes
up the iteration.

The call to "keys %fh" resets the iterator that controls the behavior
of "each". Instead of giving you the next key/value pair it gives you
the first one again. That leads to the endless loop you're observing.
Remove the line, then the loop will work as expected.
########################################################################
#ouvre_fichier.pl
########################################################################
!/usr/bin/perl
sub ouvre_fichier {
open ($F, $_[0]) || die "impossible d ouvrir le fichier : $!";
while($ligne =<$F>){
$str.= $ligne;
}
eval $str;
}
$f = 'test.dat';
while(1){
eval {
ouvre_fichier($f);#si ouvre fichier echoue, le programme ne se termine
pas };##et à mon avis c la dernier veleur utliser
last unless $@; #pas d erreur on sort de la boucle
print "$f est absent. entrez un nouveau nom de fichier $f";
chomp ($f = <STDIN>);
}

1
#######################################################################
#test.dat
#######################################################################
$Conf{XferMethod} = 'rsync';
$Conf{XferLogLevel} = '1';
$Conf{RSyncShareName} = '___1___';
$Conf{ClientNameAlias} = '___2___';

From your usage the function ouvre_fichie() is supposed to set up
a hash. As far as I can see without running it, it returns the
single value "___2___", in an incredibly convoluted manner.

Anno
I do not understand .
Indeed.

ok any more while infinite. now only a key is turned
over, ___ 2___. at the time of eval of test.dat the last value used it is
my hash I think?. ouvre_fichier should return the hach in entirety.

Then you must make it do that.

Your function ouvre_fichier() is way off the mark. It evaluates
a piece of Perl code read from test.dat. That code assigns some values
to a hash names %Conf (which is never used again). As a side effect,
it returns the last values assigned which happens to be "___2___".
The statement "%fh = ouvre_fichier($f)" makes this the only key of the
hash %h, with an undefined value.

To make the function ouvre_fichier() return the right kind of data,
change the format of test.dat to contain one blank-separated key/value
pair per line. Then use Perl's split function to retrieve the
key/value pairs and return them collectively. Putting the data
in the __DATA__ section of ouvre_fichier.pl, this is how it might
look (untested):

sub ouvre_fichier {
my @coll;
push @coll, split while <DATA>;
return @coll;
}

__DATA__
XferMethod rsync
XferLogLevel 1
RSyncShareName ___1___
ClientNameAlias ___2___

Anno
 
M

Michele Dondi

Pull the handle and lift the lid?

Yep, except that the verb "arribaltare" does not exist, but may sound
like a dialectal form of "ribaltare" and "copperchio" should be
written with one "p". Oh, and although the whole phrase is
syntactically correct in Italian, it also sounds somewhat strange with
the verbs at infinitive. But I understood it in the sense of: throw
this into the water closet and flush. All in all, if I got it right,
the most comprehensible of the OP's posts thus far. (Hence the
original reference to Darmok.)


Michele
 
J

john swilting

Michele said:
Yep, except that the verb "arribaltare" does not exist, but may sound
like a dialectal form of "ribaltare" and "copperchio" should be
written with one "p". Oh, and although the whole phrase is
syntactically correct in Italian, it also sounds somewhat strange with
the verbs at infinitive. But I understood it in the sense of: throw
this into the water closet and flush. All in all, if I got it right,
the most comprehensible of the OP's posts thus far. (Hence the
original reference to Darmok.)


Michele
1/88 day
 
M

Michele Dondi

Michele Dondi wrote: [snip]
Yep, except that the verb "arribaltare" does not exist, but may sound
like a dialectal form of "ribaltare" and "copperchio" should be
written with one "p". Oh, and although the whole phrase is
syntactically correct in Italian, it also sounds somewhat strange with
the verbs at infinitive. But I understood it in the sense of: throw
this into the water closet and flush. All in all, if I got it right,
the most comprehensible of the OP's posts thus far. (Hence the
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1/88 day

What was I saying?


Michele
 
J

john swilting

Michele said:
Michele Dondi wrote: [snip]
Yep, except that the verb "arribaltare" does not exist, but may sound
like a dialectal form of "ribaltare" and "copperchio" should be
written with one "p". Oh, and although the whole phrase is
syntactically correct in Italian, it also sounds somewhat strange with
the verbs at infinitive. But I understood it in the sense of: throw
this into the water closet and flush. All in all, if I got it right,
the most comprehensible of the OP's posts thus far. (Hence the
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1/88 day

What was I saying?


Michele
00:16:22
00:32:44
00:49:05
01:05:27
01:21:49
01:38:11
01:54:33
02:10:55
02:27:16
02:43:38
03:00:00
03:16:22
03:32:44
03:49:05
04:05:27
04:21:49
04:38:11
04:54:33
05:10:55
05:27:16
05:43:38
06:00:00
06:16:22
06:32:44
06:49:05
07:05:27
07:21:49
07:38:11
07:54:33
08:10:55
08:27:16
08:43:38
09:00:00
09:16:22
09:32:44
09:49:05
10:05:27
10:21:49
10:38:11
10:54:33
11:10:55
11:27:16
11:43:38
12:00:00
12:16:22
12:32:44
12:49:05
13:05:27
13:21:49
13:38:11
13:54:33
14:10:55
14:27:16
14:43:38
15:00:00
15:16:22
15:32:44
15:49:05
16:05:27
16:21:49
16:38:11
16:54:33
17:10:55
17:27:16
17:43:38
18:00:00
18:16:22
18:32:44
18:49:05
19:05:27
19:21:49
19:38:11
19:54:33
20:10:55
20:27:16
20:43:38
21:00:00
21:16:22
21:32:44
21:49:05
22:05:27
22:21:49
22:38:11
22:54:33
23:10:55
23:27:16
23:43:38
00:00:00
 
T

Tad McClellan

John,


Please do not drop your litter in our newsgroup.

This is a nice place, we don't want trash lying all around.

Thank you.
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top