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
3
votes
2 answers

can we do deep tie with a c++1y std::tie() -like function?

Is there a way to write a variant of std::tie in c++11/1y that ties deeply into a tuple. That is, one in which tie((x,y),z) = make_tuple(make_tuple(1,2),3) binds x, y, z to 1, 2 and 3, respectively as in the following example. It would be nice.…
thor
  • 21,418
  • 31
  • 87
  • 173
3
votes
2 answers

Is Tie::File lazily loading a file?

I'm planning on writing a simple text viewer, which I'd expect to be able to deal with very large sized files. I was thinking of using Tie::File for this, and kind of paginate the lines. Is this loading the lines lazily, or all of them at once?
Geo
  • 93,257
  • 117
  • 344
  • 520
3
votes
0 answers

Numpy: binning data with ties according to percentiles

I want to bin my data into 10 bins (histograms) using percentile ranges: bins = [0, 10th-percentile(myData), 20th-percentile(myData), 30th..., 90th-percentile(myData), +inf] So in order make a histogram out of my data, I just do: import numpy as…
Ricky Robinson
  • 21,798
  • 42
  • 129
  • 185
3
votes
1 answer

What happens if we change/update a hash value inside an each loop?

The 'perldoc -f each' say me that is not safe delete or add a value while iterating, except if the item is the most recently returned by each(). When I run this code snnipet: my ($key,$value); my %fruits = qw/ banana 1 apple 2 grape 3 /; while (…
Dinak
  • 31
  • 1
  • 3
2
votes
1 answer

Why are Netlogo links using tie not working?

The following code creates 2 cars and then adds carts behind them (called 'followers'). The code aims to spread the followers out evenly behind the cars, one after the other and then link and tie them together. Then when the cars move they should…
Kevin A
  • 71
  • 7
2
votes
1 answer

Possible to call STORE on deeper level tied hash assignment?

I'm trying to write a Perl module for a “persistent YAML hash”, with the following properties: With every access, check if the YAML file has changed, and if so, reload. As soon as any data in the hash is changed, save. Don't save on UNTIE, so that…
mscha
  • 6,509
  • 3
  • 24
  • 40
2
votes
1 answer

netlogo tie-mode "fixed" fails to maintain link-length in graphs with medium-level degree

I am trying to create a network that moves through the environment as a "static" unit, i.e. nothing in the simulation changes except the position and orientation of the whole, the position and orientation of the individual turtles relative to one…
Drew C
  • 41
  • 4
2
votes
3 answers

Outputting a Returned pair Without a Temporary

Let's say that I have a function: pair foo() I want to directly output both elements of this without using a temporary. Is there a way that I can output this, or maybe convert it into a string to output? Could I perhaps use tie to do…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
2
votes
1 answer

Constructor for tied scalar

If I were to have a simple tied scalar class that increments every time it is read I could do that like this: package Counter; use strict; use warnings; sub TIESCALAR { my $class = shift; my $value = 0; bless \$value, $class; return…
Joel Berger
  • 20,180
  • 5
  • 49
  • 104
2
votes
2 answers

What is difference between bless and tie in perl?

I was practicing some interview questions where I found this. I had a look at perldoc -f tie but couldn't get it. I know about bless and is using in my programs. Can anyone tell me what is tie and how it is related and different from bless, and its…
Kamal Nayan
  • 1,890
  • 21
  • 34
2
votes
2 answers

Hiding a tie call from the user in Perl

How can I hide a "tie" call from the user so calling an accessor will implicitly do it for them? I want to do this, because I have a data structure that can be accessed by the user, but values stored in this structure can be modified without the…
tjwrona1992
  • 8,614
  • 8
  • 35
  • 98
2
votes
1 answer

Unsafe to delete items from DB_File tied hash while iterating with `each`?

The Problem I'm using NetBSD 6.1, Perl v5.18.1, and DB_File v1.818. If I iterate over a DB_File-tied hash using each and delete each item from the hash, not all items are deleted. Here is a script demonstrating the problem: use strict; use…
Richard Hansen
  • 51,690
  • 20
  • 90
  • 97
2
votes
1 answer

Passing tied hashes using BerkelyDB to subroutines

I'm trying to pass a tied hash using BerkeleyDB to a subroutine and modifying the contents of the database in the routine, but it's not working. #!/usr/bin/perl use warnings; use strict; use BerkeleyDB; sub testdb($) { my $dbptr = shift; …
2
votes
1 answer

Ties when finding minimum in R

In the following example, how do I ask the R to select more than one index if there is a tie (For example in row 3 the minimum is 2 which occurs for both x and y columns. However, sapply gives the index for x column only) (My apologizes if this…
Metrics
  • 15,172
  • 7
  • 54
  • 83
2
votes
1 answer

In Perl, how do I detect whether a (tied) array is empty without looking at its size?

I have been tinkering with the idea of hiding some implementation details of an IPC mechanism behind a tied array. The goal is to be able to do something like this on the server side: # setup code here. Client provides a function name, we find # a…
hillu
  • 9,423
  • 4
  • 26
  • 30