eval problem!

Discussion in 'Perl Misc' started by Jim Ford, May 5, 2007.

  1. Jim Ford

    Jim Ford Guest

    I have a script using a module I've written which is used in a Tk
    callback. The module contains the following line:

    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

    The problem is that the values get determined at compile time, rather
    than updated whenever a callback is made.

    I understand that the appropriate use of 'eval' should make the call to
    localtime(time) occur during run-time, whenever the callback occurs,
    but I've not managed to get this to happen with any amount of 'mixing
    and matching'!

    I would be grateful for any suggestions.

    Jim Ford
    Jim Ford, May 5, 2007
    #1
    1. Advertising

  2. On Sat, 05 May 2007 14:02:01 GMT, Jim Ford
    <> wrote:

    >I have a script using a module I've written which is used in a Tk
    >callback. The module contains the following line:
    >
    >($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
    >
    >The problem is that the values get determined at compile time, rather
    >than updated whenever a callback is made.
    >
    >I understand that the appropriate use of 'eval' should make the call to
    > localtime(time) occur during run-time, whenever the callback occurs,
    >but I've not managed to get this to happen with any amount of 'mixing
    >and matching'!


    Do not mess with (string) eval(). Without seeing actual code, it's
    hard to say something more precise. But basically have your
    localtime(time) execute in the callback, rather than making it a
    closure around those scalars, which is what I think you're doing. (Or
    something like that.)


    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, May 5, 2007
    #2
    1. Advertising

  3. Jim Ford

    Jim Ford Guest

    Michele Dondi wrote:
    > On Sat, 05 May 2007 14:02:01 GMT, Jim Ford
    > <> wrote:
    >
    >> I have a script using a module I've written which is used in a Tk
    >> callback. The module contains the following line:
    >>
    >> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
    >>
    >> The problem is that the values get determined at compile time, rather
    >> than updated whenever a callback is made.
    >>
    >> I understand that the appropriate use of 'eval' should make the call to
    >> localtime(time) occur during run-time, whenever the callback occurs,
    >> but I've not managed to get this to happen with any amount of 'mixing
    >> and matching'!

    >
    > Do not mess with (string) eval(). Without seeing actual code, it's
    > hard to say something more precise. But basically have your
    > localtime(time) execute in the callback, rather than making it a
    > closure around those scalars, which is what I think you're doing. (Or
    > something like that.)


    Thanks for the reply, Michele.

    I have '($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
    localtime(time);' in a module that I've written that relates the time of
    day to a teaching period. I call the module subroutine day_period() in
    the callback which returns the day of the week and the teaching period
    eg (Tuesday,5b). So localtime(time) _is_ called in the callback via the
    module subroutine day_period().

    NB. I'm not really up to speed with closures - I've read the section in
    the 'Programming Perl', but need time for it to soak in!

    Jim
    Jim Ford, May 5, 2007
    #3
  4. On Sat, 05 May 2007 15:25:47 GMT, Jim Ford
    <> wrote:

    >I have '($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
    >localtime(time);' in a module that I've written that relates the time of


    This doesn't mean anything. Are those variables lexical? I don't think
    so. And without seeing *how* that particular statement is used in your
    particular module, one can hardly say anything.

    >day to a teaching period. I call the module subroutine day_period() in
    >the callback which returns the day of the week and the teaching period
    >eg (Tuesday,5b). So localtime(time) _is_ called in the callback via the
    >module subroutine day_period().


    Still not clear. Can't you prepare -as is usually recommended- a
    minimal but complete example exhibiting the problem?

    >NB. I'm not really up to speed with closures - I've read the section in
    >the 'Programming Perl', but need time for it to soak in!


    Less trascendental than at first sight it may seem.


    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, May 5, 2007
    #4
  5. Jim Ford wrote:
    > I have a script using a module I've written which is used in a Tk
    > callback. The module contains the following line:
    >
    > ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
    >
    > The problem is that the values get determined at compile time, rather
    > than updated whenever a callback is made.
    >
    > I understand that the appropriate use of 'eval' should make the call to
    > localtime(time) occur during run-time, whenever the callback occurs,
    > but I've not managed to get this to happen with any amount of 'mixing
    > and matching'!


    If localtime() won't run then eval() won't run either. It sounds like your
    "callback" is not really a callback but a call. Show us your actual code.



    John
    --
    Perl isn't a toolbox, but a small machine shop where you can special-order
    certain sorts of tools at low cost and in short order. -- Larry Wall
    John W. Krahn, May 5, 2007
    #5
  6. Jim Ford

    Jim Ford Guest

    Michele Dondi wrote:
    > On Sat, 05 May 2007 15:25:47 GMT, Jim Ford
    > <> wrote:
    >
    >> I have '($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
    >> localtime(time);' in a module that I've written that relates the time of

    >
    > This doesn't mean anything. Are those variables lexical? I don't think
    > so. And without seeing *how* that particular statement is used in your
    > particular module, one can hardly say anything.
    >
    >> day to a teaching period. I call the module subroutine day_period() in
    >> the callback which returns the day of the week and the teaching period
    >> eg (Tuesday,5b). So localtime(time) _is_ called in the callback via the
    >> module subroutine day_period().

    >
    > Still not clear. Can't you prepare -as is usually recommended- a
    > minimal but complete example exhibiting the problem?
    >


    Thanks again for the reply, Michele (& John).

    When I get back to work (where I'm running the script) I'll pick up the
    scripts and post the relevant parts.

    Jim Ford
    Jim Ford, May 5, 2007
    #6
  7. Jim Ford

    Uri Guttman Guest

    >>>>> "JF" == Jim Ford <> writes:


    JF> When I get back to work (where I'm running the script) I'll pick up the
    JF> scripts and post the relevant parts.

    you are missing the point. try to create a small COMPLETE script that
    illustrates your problem. most of the time snippets aren't good enough
    as critical parts are omitted. we see snippets with no data, snippets
    that assumes too much that is unseen, etc.

    a complete script can be downloaded and run so we can see the same
    bugs/errors as the poster claims. then it is also easier for someone to
    debug it and help you. there are times when a couple of lines if code is
    enough as when it is already working but you want a better way to do it.

    uri

    --
    Uri Guttman ------ -------- http://www.stemsystems.com
    --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
    Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
    Uri Guttman, May 5, 2007
    #7
  8. Jim Ford

    Jim Ford Guest

    Uri Guttman wrote:
    >>>>>> "JF" == Jim Ford <> writes:

    >
    >
    > JF> When I get back to work (where I'm running the script) I'll pick up the
    > JF> scripts and post the relevant parts.
    >
    > you are missing the point. try to create a small COMPLETE script that
    > illustrates your problem. most of the time snippets aren't good enough
    > as critical parts are omitted. we see snippets with no data, snippets
    > that assumes too much that is unseen, etc.
    >
    > a complete script can be downloaded and run so we can see the same
    > bugs/errors as the poster claims. then it is also easier for someone to
    > debug it and help you. there are times when a couple of lines if code is
    > enough as when it is already working but you want a better way to do it.
    >


    Got it - thanks Uri!

    Jim
    Jim Ford, May 5, 2007
    #8
  9. Jim Ford

    Jim Ford Guest

    Jim Ford wrote:
    > I have a script using a module I've written which is used in a Tk
    > callback. The module contains the following line:
    >
    > ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);


    Sorted!

    While stripping the code down in order to provide a concise version to
    show here, I discovered a coding logic error.

    Thanks to those who responded and prompted me to pare the code down, and
    thus find the problem!

    Jim Ford
    Jim Ford, May 6, 2007
    #9
    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. Eric Newton
    Replies:
    3
    Views:
    9,378
    Brock Allen
    Apr 4, 2005
  2. DataBinder.Eval and Eval.

    , Jun 16, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    538
    Karl Seguin [MVP]
    Jun 16, 2006
  3. Alex van der Spek

    eval('07') works, eval('08') fails, why?

    Alex van der Spek, Jan 8, 2009, in forum: Python
    Replies:
    6
    Views:
    1,425
    Bruno Desthuilliers
    Jan 8, 2009
  4. Liang Wang
    Replies:
    8
    Views:
    128
    Ben Morrow
    Feb 2, 2008
  5. Marc Girod

    to eval or not to eval?

    Marc Girod, Apr 19, 2011, in forum: Perl Misc
    Replies:
    2
    Views:
    153
    Marc Girod
    Apr 19, 2011
Loading...

Share This Page