Hi, Monks ...

I've tried my brains out to understand tying variables (read perltie, all the tie manpages, the tie tutorial here; I even opened my Conway book, all to no avail.)

What I want to do is to tie the scalar variable "$tie" to the output of localtime(), so that each time I use $tie, I get the current time.

It's silly to even include my pathetic attempt, but ...
#!/usr/bin/perl -w use strict; use Tie::Scalar; use vars qw($now); tie ($now, localtime()); print "$now\n"; sleep 5; print "$now\n";

... which results in ...
Can't locate object method "TIESCALAR" via package "Mon Sep 24 21:29:5 +0 2001" at tienow.pl line 7.

I'm sure I'd know how to do this if I understood the first thing about OO programming, but I find that to be another opaque subject. Perhaps I'll ask about that later, but could someone explain how to do what I want to do, or at least push me further in the right direction, please?

Thanks ... --blueflashlight

In reply to Need simple example tying scalar to localtime() by blueflashlight

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.