great and better hash eval

Discussion in 'Perl Misc' started by john swilting, Aug 26, 2007.

  1. 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___';
     
    john swilting, Aug 26, 2007
    #1
    1. Advertising

  2. john swilting

    -berlin.de Guest

    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 = <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
     
    -berlin.de, Aug 26, 2007
    #2
    1. Advertising

  3. 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^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
     
    Michele Dondi, Aug 26, 2007
    #3
  4. -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 = <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 ?
     
    john swilting, Aug 26, 2007
    #4
  5. john swilting

    -berlin.de Guest

    john swilting <> wrote in comp.lang.perl.misc:
    > -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 = <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
     
    -berlin.de, Aug 26, 2007
    #5
  6. 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
     
    john swilting, Aug 27, 2007
    #6
  7. 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^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
     
    Michele Dondi, Aug 28, 2007
    #7
  8. john swilting

    -berlin.de Guest

    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
     
    -berlin.de, Aug 28, 2007
    #8
  9. On 28 Aug 2007 14:42:32 GMT, -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^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
     
    Michele Dondi, Aug 28, 2007
    #9
  10. Michele Dondi wrote:

    > On 28 Aug 2007 14:42:32 GMT, -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
     
    john swilting, Aug 29, 2007
    #10
  11. 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^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
     
    Michele Dondi, Aug 29, 2007
    #11
  12. 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
     
    john swilting, Aug 30, 2007
    #12
  13. 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/"
     
    Tad McClellan, Aug 31, 2007
    #13
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DataBinder.Eval and Eval.

    , Jun 16, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    580
    Karl Seguin [MVP]
    Jun 16, 2006
  2. rp
    Replies:
    1
    Views:
    584
    red floyd
    Nov 10, 2011
  3. Eric I.
    Replies:
    0
    Views:
    286
    Eric I.
    Oct 5, 2008
  4. john swilting

    better and great hash

    john swilting, Aug 25, 2007, in forum: Perl Misc
    Replies:
    2
    Views:
    90
    Tad McClellan
    Aug 25, 2007
  5. Liang Wang
    Replies:
    8
    Views:
    156
    Ben Morrow
    Feb 2, 2008
Loading...

Share This Page