efreed has asked for the wisdom of the Perl Monks concerning the following question:

I want to dump a lot of info from a database to a file on my local machine. I could not find a DBI module for the database (Intersystems's CACHE--"the post-relational database"). So I wanted to try Net::Telnet, telnet to the system, dump the data to st-out, and then edit it and dump it, but Net::Telnet buffers all output (or is it input?) and I would have to make the buffer super big, and the data will certainly fill up memory anyway. Ideally I would use while(), like a large file and then print to a file, or something. Any ideas, oh wise monks?

Replies are listed 'Best First'.
Re: Non buffered telnet?
by talexb (Chancellor) on Jan 20, 2003 at 22:00 UTC

    While not exactly a Perl answer, my suggestion would be just to use the SQL command line to do a SELECT on the table(s) that you want, and send the output (suitably field and line-terminated) to an output file. Then just use scp or ftp to grab that output file.

    --t. alex
    Life is short: get busy!
Re: Non buffered telnet?
by tekkie (Beadle) on Jan 21, 2003 at 14:33 UTC
    You could easily make use of the Net::Telnet->recv() subroutine here, it allows you to specify how many bytes you'd like to receive at a time like so:

    $tel->recv($buffer, 512);

    Would retrieve 512 bytes from the $tel object into the $buffer scalar.

    If you were simply retrieving the data for storage, it'd be pretty simple to write something like this:

    open(OUTPUT, '>output.file'); while($tel->recv($buffer, 512)) { print OUTPUT $buffer; } close OUTPUT;
    However, you noted that you'll be further editing the data before you're done with it, and also I get the sense that memory seems to be a primary concern in the issue.

    One solution to this would be to use IO::File to create a temporary file to store the data in until you're done editing it:

    my $output = IO::File->new_tmpfile(); while($tel->recv($buffer, 512)) { $output->print($buffer); }
    Now, all of the output from your telnet session has been stored in the $output temporary file which you can use for further parsing and editing.