Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Friends,

My script uses way too much memory. I haven't ever use tie before. So I thought I could use Tie::File to store my data to disk rather than memory. Here's what I tried to do ...
#!/usr/local/bin/perl -w use strict; use Data::Dumper; use Tie::File; use lib('.'); use board; use hole; use boardTree; # # create the holes # my $holeLevel = 0; my @holes; for my $i (0..15){ $holeLevel = 1 if $i >0; $holeLevel = 2 if $i >2; $holeLevel = 3 if $i >5; $holeLevel = 4 if $i >9; push ( @holes, new hole( 'white', $i, $holeLevel, undef ) ); } # # link the holes # $holes[0]->setLinks( [ $holes[1], $holes[2] ] ); $holes[1]->setLinks( [ $holes[0], $holes[2], $holes[3], $holes[4] ] ) +; $holes[2]->setLinks( [ $holes[0], $holes[1], $holes[4], $holes[5] ] ) +; $holes[3]->setLinks( [ $holes[1], $holes[4], $holes[6], $holes[7] ] ) +; $holes[4]->setLinks( [ $holes[1], $holes[2], $holes[3], $holes[5], $h +oles[7], $holes[8] ] ); $holes[5]->setLinks( [ $holes[2], $holes[4], $holes[8], $holes[9] ] ) +; $holes[6]->setLinks( [ $holes[3], $holes[7], $holes[10], $holes[11] ] + ); $holes[7]->setLinks( [ $holes[3], $holes[4], $holes[6], $holes[8], $h +oles[11], $holes[12] ] ); $holes[8]->setLinks( [ $holes[4], $holes[5], $holes[7], $holes[9], $h +oles[12], $holes[13] ] ); $holes[9]->setLinks( [ $holes[5], $holes[8], $holes[13], $holes[14] ] + ); $holes[10]->setLinks( [ $holes[6], $holes[11] ] ); $holes[11]->setLinks( [ $holes[6], $holes[7], $holes[10], $holes[12] ] + ); $holes[12]->setLinks( [ $holes[7], $holes[8], $holes[11], $holes[13] ] + ); $holes[13]->setLinks( [ $holes[8], $holes[9], $holes[12], $holes[14] ] + ); $holes[14]->setLinks( [ $holes[9], $holes[13] ] ); my $BT = new boardTree ( new board( \@holes, 0 ), 1, 1, [ new boardTre +e( new board ( undef, 1 ), 1, 1, [] ) ] ); # # lets try tie the boardTree object to a file # tie $BT, 'Tie::File', "thetiefile"; # I am guess that the script is dying because # this will use up too much virtual memory and # the OS (Window XP) kills the script. $BT->{'links'}[0]->makeLinks(); # I never get here because of memory issue $BT->dumpPretty();
... here's the output I get ...
$ ./tieBoardTree.pl Can't locate object method "TIESCALAR" via package "Tie::File" at ./tieBoardTree.pl line 47 (#1) (F) You called a method correctly, and it correctly indicated a pa +ckage functioning as a class, but that package doesn't define that parti +cular method, nor does any of its base classes. See perlobj. Uncaught exception from user code: Can't locate object method "TIESCALAR" via package "Tie::File" + at ./tieBoardTree.pl line 47.
Like I said I have never used tie before. Maybe tie is completely the wrong thing to use here. If so what should I do?

Plankton: 1% Evil, 99% Hot Gas.

edit (broquaint): changed <pre> tags to <code>


In reply to Should I be using tie for this? by Plankton

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-24 02:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found