great and better hash eval
great and better hash eval
am 26.08.2007 01:26:42 von 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 = );
}
1
############################################################ ###########
#test.dat
############################################################ ###########
$Conf{XferMethod} = 'rsync';
$Conf{XferLogLevel} = '1';
$Conf{RSyncShareName} = '___1___';
$Conf{ClientNameAlias} = '___2___';
Re: great and better hash eval
am 26.08.2007 02:07:10 von dformosa
On Sun, 26 Aug 2007 01:26:42 +0200, john swilting wrote:
> 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;
>}
Hashes have an iterator, this is used by each, values and keys to step
though the hash. By calling keys at the bottem of your while loop
your resetting the iterator and causing yourself to go into an
infinite loop.
Re: great and better hash eval
am 26.08.2007 02:27:42 von anno4000
john swilting wrote in comp.lang.perl.misc:
> 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 = );
> }
>
> 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
Re: great and better hash eval
am 26.08.2007 11:28:43 von Michele Dondi
On Sun, 26 Aug 2007 01:26:42 +0200, john swilting
wrote:
>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
http://en.wikipedia.org/wiki/Darmok
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
Re: great and better hash eval
am 26.08.2007 18:38:04 von john.swilting
anno4000@radom.zrz.tu-berlin.de wrote:
> john swilting wrote in comp.lang.perl.misc:
>> 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){
#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 = );
>> }
>>
>> 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 ?
Re: great and better hash eval
am 26.08.2007 20:45:14 von anno4000
john swilting wrote in comp.lang.perl.misc:
> anno4000@radom.zrz.tu-berlin.de wrote:
>
> > john swilting wrote in comp.lang.perl.misc:
> >> 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){
>
> #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 = );
> >> }
> >>
> >> 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 ;
return @coll;
}
__DATA__
XferMethod rsync
XferLogLevel 1
RSyncShareName ___1___
ClientNameAlias ___2___
Anno
Re: great and better hash eval
am 27.08.2007 12:00:32 von john.swilting
Michele Dondi wrote:
> On Sun, 26 Aug 2007 01:26:42 +0200, john swilting
> wrote:
>
>>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
>
> http://en.wikipedia.org/wiki/Darmok
>
>
> Michele
tirare la maniglia e arribaltare il copperchio
Re: great and better hash eval
am 28.08.2007 13:08:49 von Michele Dondi
On Mon, 27 Aug 2007 12:00:32 +0200, john swilting
wrote:
>> http://en.wikipedia.org/wiki/Darmok
>>
>>
>> Michele
>tirare la maniglia e arribaltare il copperchio
:)
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
Re: great and better hash eval
am 28.08.2007 16:42:32 von anno4000
Michele Dondi wrote in comp.lang.perl.misc:
> On Mon, 27 Aug 2007 12:00:32 +0200, john swilting
> wrote:
>
> >> http://en.wikipedia.org/wiki/Darmok
> >>
> >>
> >> Michele
> >tirare la maniglia e arribaltare il copperchio
Pull the handle and lift the lid?
Anno
Re: great and better hash eval
am 28.08.2007 19:46:08 von Michele Dondi
On 28 Aug 2007 14:42:32 GMT, anno4000@radom.zrz.tu-berlin.de wrote:
>> >tirare la maniglia e arribaltare il copperchio
>
>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
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
Re: great and better hash eval
am 29.08.2007 16:25:23 von john.swilting
Michele Dondi wrote:
> On 28 Aug 2007 14:42:32 GMT, anno4000@radom.zrz.tu-berlin.de wrote:
>
>>> >tirare la maniglia e arribaltare il copperchio
>>
>>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
1/88 day
Re: great and better hash eval
am 29.08.2007 17:14:56 von Michele Dondi
On Wed, 29 Aug 2007 16:25:23 +0200, john swilting
wrote:
>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
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
Re: great and better hash eval
am 30.08.2007 17:30:10 von john.swilting
Michele Dondi wrote:
> On Wed, 29 Aug 2007 16:25:23 +0200, john swilting
> wrote:
>
>>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
Re: great and better hash eval
am 31.08.2007 01:10:11 von Tad McClellan
john swilting wrote:
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.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"