Utiliser le module DB_file associé à la fonction tie avec le format DB_RECNO :
Le premier script sauvegarde le tableau :
#!/usr/local/bin/perl
use strict;
use IO::Handle;
use DB_File;
STDOUT -> autoflush(1);
my @h;
my $db = tie(@h,'DB_File',"tmp_file.db",O_CREAT|O_RDWR, 0600,$DB_RECNO)
or die $!;
for(my $x = 0; $x <= 100; $x++)
{
$h[$x] = int(rand(100));
print $h[$x]."\n";
}
$db -> sync;
untie(@h);
Le second script lit et affiche les données :
#!/usr/local/bin/perl
use strict;
use IO::Handle;
use DB_File;
STDOUT -> autoflush(1);
my @h;
my $db = tie(@h,'DB_File',"tmp_file.db",O_WRONLY,0600,$DB_RECNO) or die $!;
foreach my $value(@h)
{
print "$value\n";
}
$db -> sync;
untie(@h);
Plus d'informations dans la documentation de Perl :