Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Tie::File and Tie::Array::Packed;

by Dandello (Scribe)
on Feb 01, 2011 at 16:02 UTC ( #885528=perlquestion: print w/replies, xml ) Need Help??
Dandello has asked for the wisdom of the Perl Monks concerning the following question:

Not a question so much as an observation - Tie::File and Tie::Array::Packed don't seem to play well together. (At least not the versions I have.)

When reading from a tied file data that will be processed and put into the tied and packed array (to save on memory usage), the output from the tied file is wrong. But if I don't tie and pack the array the data is going into, it works fine.

Weird, huh?

Replies are listed 'Best First'.
Re: Tie::File and Tie::Array::Packed;
by Corion (Pope) on Feb 01, 2011 at 16:08 UTC

    You don't show any code, and from your description, it's not exactly clear to me what you have. I interpret your description as something like the following:

    tie my @in, 'Tie::File', $filename; tie my @mem, 'Tie::Array::Packed', ...; @mem = @in; # sluuuurp print "@in";

    And your claim is that the output from print is not what you expect.

    Can you provide us with self-contained (small) code and (small) data that reproduces the problem?

Re: Tie::File and Tie::Array::Packed;
by salva (Abbot) on Feb 01, 2011 at 16:10 UTC
    Could you post some code showing the problem?

    (BTW, I am the author of Tie::Array::Packed)

      Unfortunately, small is not what this is about.

      The two input files: 'tmp/datatest.txt' 1|112|3|21|newtest|1|1296499858|0,10,15,20,25,30,35,40,45,|5,10,15,10,15,25,20,30,20,| and 'tmp/test.txt'

      And the not exactly a small piece of code:

      As you can see, it's not exactly straight forward. Line '$y' is read from the tied file @aod, and the $x letter determines the behavior of sub popnum1 which uses the tied array @aob.

      But when @aob is tied, I get the error 'Can't use string ("28426980") as an ARRAY ref while in "strict refs" in use at C:\testing\ line 125 <$fh> line 1.'

      But, if I forgo tying @aob, then everything's fine.

        Can you please try reducing your code until it becomes small and all the bits unrelated to the problem at hand have been removed?

        At first glance at least some of these lines are not related to the problem:

        use strict; #use warnings; use CGI::Carp; # can go use List::Util qw(sum); # can go use Math::Random::MT qw(rand); # can go #use Math::Random::MT::Auto qw(rand); use Tie::Array::Packed; use Tie::File;

        Please do invest the effort of reducing your script to a small, self-contained script that still exhibits the problem.

        I am unable to reproduce the error in my computer. When I run your script I get a DONE!! message.

        Which perl version and OS are you using?

        Also, could you follow Corion advice trying to reduce the script to something minimal?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://885528]
Approved by Corion
[james28909]: politicians making jobs for themselves? that is absurd! we all know how hard those politicians have it, having to take millions from lobbiest while screwing over their citizens. have a little sympathy why dont ya!

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2017-12-15 18:33 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (442 votes). Check out past polls.