Hi Perrin,

No, if the message you're getting is to use globals instead of
lexicals then you've got it all wrong.

- Use lexicals for everything, unless you actually want the value to
persist across requests.
I was thinking, for large amounts of data, about using globals.
Indeed, imagine you have several different scripts that could potentially use large amounts of data. Then, using a global variable would save me the need to allocate for each script different memory locations that would anyway never be used at once (memory is allocated per Perl Intepreter) For example, instead of using a "my $bigdata" in 50 different script, that could this result in big memory allocation, I would use a unique $mypack::bigdata in each script, so that each script would share the same memory address for this potentially large data.buffer.
I know it is not elegant, but this could help me save lots of memory.

Another solution would be to undef potentially big lexical variables after they are used, so that the memory could be used by other scripts.

- Don't load large amounts of data into scalars.
Fine. Now I know why. But sometimes, you don't have the choice.

- Use mysql_use_result if you have to load a very large result set.
Ideally you should avoid this by using LIMIT and OFFSET.
I tried to use "mysql_use_result" this morning, but without success.

Actually, I tried this script:

use strict;
package mypack;
use DBI;
my $dbh;
my $sth;
$dbh = DBI->connect('DBI:mysql:boardwalk;host=82.228.218.209;', 'root', '');
$dbh->{mysql_use_result} = 1;
$sth = $dbh->prepare('SELECT * FROM account');
$sth->execute();

Normally, as mysql_use_result is set, if I understand well how things should be working, , no data should be retrieved from the DB at this stage (but only when fetching rows). However, all the query data is fetched anyway. (I could see the packets transitting from MySQL). I don't exactly know why, and am wondering if there is a setting to enable its use from MySQL point of view. (I am using MySQL Server 5.0.27 in a Windows installation)


Does that make sense?

- Perrin


Reply via email to