I'm posting this under General since I'm debating between multiple languages, and this is really more about efficiency than the language. @phranque, I'll totally understand if you need to move it :-D
I have a Perl script that I import to other scripts via:
eval { require 'whatever.filter' };
This script has 4 associative arrays, totaling about 12k worth of data. The whole script is bout 42kb, so a little under 1/4 of it is these arrays. I don't modify them TOO often, maybe a few times a month.
I'm thinking about moving them to a MySQL table with 3 columns: array_name (EN
UM with 4 possible values), key (VAR
CHAR), and value (VAR
CHAR). Then I could replace the 12kb of data in the script with this, which is more like 271 bytes:
# already using this module, so it's just here for your reference
use DBI;
my $sth = $dbh->prepare("SELECT array_name, key, value FROM table")
or die "prepare statement failed: $dbh->errstr()";
$sth->execute()
or die "execution failed: $dbh->errstr()";
while (($array_name, $key, $value) = $sth->fetchrow()) {
$$array_name{$key} = $value;
}
Pros:
1. Smaller script means it would compile marginally faster
2. Moving these to MySQL means no real chance for a syntax error, so I could (probably) remove the EVAL function
Cons:
1. Harder to read
2. Each run is another MySQL query
3. It would take longer to process due to the query time of MySQL
Can you think of any other pros or cons? What would you do?