I saw a few problems. Check out perltie for more details as to how this all works.

The constructor seems fine...

package Celcius; sub TIESCALAR { my $class=shift; my $data=shift; return bless \$data, $class; }
Your version of STORE didn't actually STORE the change...
sub STORE{ my $self=shift; my $data=shift; $$self = ($data*(9/5)+32); }
And last, FETCH only takes one argument, and it's that one argument you should dereference.
sub FETCH{ my $self=shift; return $$self; } 1;

If you're interested, here's the test code I used to try out my version:

#!/usr/bin/perl -w use strict; use Celcius; my $temp; tie $temp, 'Celcius'; $temp = 0; print "Initial temp is $temp (C)\n"; while(<>) { chomp; $temp = $_; print "Temp is $_ (F) ($temp (C))\n"; }
As an alternative, you could store the Farenheit temp, and do the conversion in FETCH when you return the value.

Oh, and I think it's spelled "Celsius", but I'm not sure :)
--
Mike


In reply to Re: Problems using ties by RMGir
in thread Problems using ties by Popcorn Dave

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.