Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Tying

by merlyn (Sage)
on Sep 25, 2001 at 08:50 UTC ( #114483=note: print w/ replies, xml ) Need Help??


in reply to Need simple example tying scalar to localtime()

untested, but I think I'll get this right. :)

{ package Tie_timer; sub TIESCALAR { bless {}, shift } sub FETCH { scalar localtime } } tie $now, Tie_timer; print $now;

-- Randal L. Schwartz, Perl hacker


Comment on Re: Tying
Download Code
Replies are listed 'Best First'.
Re: Re: Tying
by blueflashlight (Pilgrim) on Sep 25, 2001 at 09:09 UTC
    you are my hero.

    Taking your example, and my pathetic perl ability, I came up with:
    #!/usr/bin/perl -w use strict; use Tie::Scalar; package Tie_timer; sub TIESCALAR { bless {}, shift } sub FETCH { scalar localtime } package main; my $now; tie ($now, "Tie_timer"); print "$now\n"; sleep 5; print "$now\n"

    ... which worked perfectly. Perhaps I even understand it better.

    thanks again. --sandy

      It's a small thing, but you don't actually need to use Tie::Scalar. You're not using anything from it.

      --
      <http://www.dave.org.uk>

      "The first rule of Perl club is you don't talk about Perl club."

        really? I didn't realize that "tie" was a built-in. while I like modules as much as the next guy, It's great that this is one less then I need to use.

        Thanks, --Sandy

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://114483]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2015-07-08 07:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (96 votes), past polls