Questions tagged [tie]

Perl command to hide an object class in a simple variable.

Perl command to hide an object class in a simple variable. See also: http://perldoc.perl.org/functions/tie.html.

86 questions
4
votes
3 answers

Tie variable multiple times

Can I tie a variable multiple times? I'd try it myself, but I'm not sure of the syntax. I want to tie a hash to Cache::Memcached::Tie and IPC::Shareable.
Glen Solsberry
  • 11,960
  • 15
  • 69
  • 94
4
votes
1 answer

perl5140delta localized tied variables

perl5140delta says that localized tied variables are no long tied. This change was implemented in 5.13.1 but reverted in 5.13.2. Is this back in 5.14 (from my testing it does not appear to be) or is the delta for 5.14.0 incorrect? I care because I…
Joel Berger
  • 20,180
  • 5
  • 49
  • 104
4
votes
3 answers

How to watch particular hash key for changing its value?

I have a hash, e.g. $hash->{'foo'}{'bar'}. I want to call Carp::cluck in any place where value of bar key changed. How to do that ? Is there any ready module on CPAN that can do that trick ?
Paul Serikov
  • 2,550
  • 2
  • 21
  • 36
4
votes
2 answers

What is the common idea of perl modules with Tie:: namespace?

There are a lot of modules with Tie::namespace on CPAN - Tie::Hash, Tie::Sub, Tie::Cache, Tie::DBI, etc. What is common among them ? I checked perltie but 'm not sure that I understood the concept clear. Could someone explain it?
Paul Serikov
  • 2,550
  • 2
  • 21
  • 36
4
votes
3 answers

Perl reading only specific gz file lines

I'm trying to make a parsing script that parses a huge text file (2 million+ lines) that is gunzip compressed. I only want to parse a range of lines in the text file. So far I've used zgrep -n to find the two lines that mentions the string that I…
Anfoni
  • 43
  • 5
4
votes
4 answers

returning a lazily-computed scalar, in perl

I'm trying to add some functionality to our code base by using tied scalars. We have a function which is specified to return scalars. I thought I could add some features to the system by tie-ing these scalars before returning them, but it looks like…
bukzor
  • 37,539
  • 11
  • 77
  • 111
4
votes
4 answers

Why is the variable still tied

Running: $t = 3; { tie $t, 'Yep'; } # Expect $t to become untied here. print $t; package Yep; sub TIESCALAR { bless {}, 'Yep'; } sub UNTIE { print "UNTIE\n"; } sub DESTROY { print "DESTROY\n"; } The output is: Can't locate object…
Eugen Konkov
  • 22,193
  • 17
  • 108
  • 158
4
votes
2 answers

How can I prevent perl from reading past the end of a tied array that shrinks when accessed?

Is there any way to force Perl to call FETCHSIZE on a tied array before each call to FETCH? My tied array knows its maximum size, but could shrink from this size depending on the results of earlier FETCH calls. here is a contrived example that…
Eric Strom
  • 39,821
  • 2
  • 80
  • 152
4
votes
1 answer

Perl Cannot Binmode STDOUT After Untie Filehandle

I need to disable progressive buffering of an HTTP response. I've got this working in Perl using a file handle class: $|=1; $TIE = tie(*STDOUT,__PACKAGE__); Print statements are stored in an array and are retrieved via the following: $buffer = tied…
xpsd300
  • 175
  • 2
  • 11
3
votes
1 answer

Unexpected behavior when using Tie::File on __DATA__

In trying to answer an old question in a clever way, I was going to attempt this, not knowing if it would succeed: #!/usr/bin/env perl use strict; use warnings; use Tie::File; tie( my @data, 'Tie::File', \*DATA ) or die "Cannot tie DATA"; foreach…
Joel Berger
  • 20,180
  • 5
  • 49
  • 104
3
votes
1 answer

Can you tie() a filehandle without a bareword glob?

I'm trying to use Device::SerialPort without a bareword glob, see questions at the bottom. Here is their example: $PortObj = tie (*FH, 'Device::SerialPort', $Configuration_File_Name) print FH "text"; ... but polluting the namespace with *FH feels…
KJ7LNW
  • 1,437
  • 5
  • 11
3
votes
1 answer

Why can't Win32::TieRegistry list subkeys?

Using Cygwin Perl v5.8.8 and Win32::TieRegistry 0.26. We can get a tied hash object thing for HKEY_CURRENT_USER: $ perl -e ' my %RegHash; use Win32::TieRegistry( TiedHash => \%RegHash ); use Data::Dumper; my $Key =…
Martin Fido
  • 1,070
  • 11
  • 12
3
votes
1 answer

Is an Incremented Variable Reusable in a tie Call?

So I understand that re-usage of a variable that has been post incremented is undefined behavior in a function call. My understanding is this is not a problem in constructors. My question is about tie which is oddly halfway between each. Given:…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
3
votes
2 answers

Can I use tie to put Elements of a pair in a vector?

So lets say that I have a function like: pair func() and a vector vec. I want to do this: vec.resize(size(vec) + 2U); tie(*next(rbegin(vec)), *rbegin(vec)) = func(); I just feel like this is a really complicated way to write what…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
3
votes
2 answers

Perl: Trouble storing a huge hash on disk?

I am working on a Perl project that involves building a hash with about 17 million keys. This is too big to be stored in memory (my laptop's memory will only hold about 10 million keys). I know that the solution is to store the data on disk, but…
dannyhmg
  • 135
  • 8