tie trouble 
Author Message
 tie trouble

I'm writing a little module, based on Compress::Zlib, to provide
scalars, arrays and hashes that  transparently compress themselves for
storage and decompress themselves when they're needed.  The idea,
obviously, is to reduce the memory footprint of programs that store
large amounts of data where increased CPU time isn't a problem.  I'll
publish and GPL the module when it's finished.

What I'm finding, though, is that references don't work the way I'd
like.  Actually, they don't work at all.  Here's some sample code, which
you obviously won't be able to run:

        #!perl -w
        use strict;

        use Compress::Var;      # the new module

        my $var;
        tie $var, 'Compress::Var', 'Contents';
        print "\$var is '$var'\n";

        $var = 'Something else';
        print "\$var is '$var'\n";

        my $rvar = \$var;
        print "Through reference: '$$rvar'\n";

This code prints:

        $var is 'Contents'
        $var is 'Something else'
        Through reference: ''

Is there any way to make references work with tied variables?  Or do I
need to throw the whole thing away and start again with a new module and
overloaded operators?

In case it matters, I'm using ActiveState's build 509, based on Perl
5.005_02.

Markus

--
Delete the 'delete this bit' bit of my address to reply



Wed, 01 Aug 2001 03:00:00 GMT  
 tie trouble

Quote:

> What I'm finding, though, is that references don't work the way I'd
> like.  Actually, they don't work at all.

Please ignore my previous posting.  I was bitten by a pice of
undocumented functionality in another module, which overwrote an input
buffer without warning and therefore caused my code to fail the second
time it was called.

Apologies to everyone whose time was wasted.

Markus

--
Delete the 'delete this bit' bit of my address to reply



Fri, 03 Aug 2001 03:00:00 GMT  
 tie trouble

Quote:

> Is there any way to make references work with tied variables?

This works as expected for me...  Does it work for you?

   #!/usr/bin/perl -w
   use strict;

   package Foo;
   sub TIESCALAR { return bless {foo => ''}, 'Foo' }
   sub FETCH { print "[Fetching]\n"; return $_[0]->{foo} }
   sub STORE { print "[Storing $_[1]]\n"; $_[0]->{foo} = $_[1] }

   package main;
   tie my $afoo, 'Foo';
   $afoo = 'bar';
   my $rfoo = \$afoo;
   print "$afoo\n";
   print "$$rfoo\n";
   __END__
   [Storing bar]
   [Fetching]
   bar
   [Fetching]
   bar

--

http://pobox.com/~jdf



Fri, 03 Aug 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. tie troubles with MOJO

2. tie() troubles

3. tie() troubles

4. BETA TEST: Tk::Tie::MenuHash - Ties a Tk::Menubutton widget to a hash, kinda

5. PERL coredumps with tie but not tied

6. Proposal... Tie::RangeHash or Tie::Range

7. PERL coredumps with tie but not tied

8. bizarre(?) problem, tied hash of tied hashes

9. Tie/bless vs. bless/tie and segmentation fault

10. BETA TEST: Tk::Tie::MenuHash - Ties a Tk::Menubutton widget to a hash, kinda

11. use tie from Tie::File "invalid argument" problem

12. Weird problem with tied hash of tied hashes (DBI problem?)

 

 
Powered by phpBB® Forum Software