Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Prob avec optimisation de mémoire

Aucune réponse
Avatar
Orion93
Bonjour,

J'ai fais un petit script perl pour lister les fichiers ne repondant pas à
certains types d'extensions. Il n'est pas très beau mais il fonctionne pour
une petite arbo par contre quand je l'exécute sur une arborescence
importante avec beaucoup de fichiers, il plante ma machine avec une erreur
de type plus de memoire. Aussi je voudrais savoir comment faire pour
optimiser les ressources mémoires (vidage ou restreindre la taille memoire
du programme) j'ai essayé qqchose comme $^M qui a priori sert à vider la
mémoire d'urgence avant un "out memory" mais je n'ai rien trouver sur son
fonctionnement.

Merci de votre aide

Sophie

#!/usr/bin/perl
use strict;
use warnings;
use Tk;
use diagnostics;
use Tk::Entry;

my $main = MainWindow -> new;
$main -> title("Test 1");
$main -> Label(-text=>"Chemin:")->pack();
my $toto = $main -> Entry()->pack(-padx=>5);
$main -> Label(-text=>"Chemin avec fichier en txt\n pour le résultat:")-
>pack();
my $toto1 = $main -> Entry()->pack(-padx=>5);
$main->Button(-text=>'Ok',-command=>\&listePages)->pack(-side=>'left',
expand=>1,-pady=>5);
$main->Button(-text=>'Fermer',-command=>sub {exit;})->pack(-side=>'right',
expand=>1,-pady=>1);
MainLoop();
my $i=0;
my %tabRep;


sub recupPages{
my $strDir=shift;
my $nomFic;
$tabRep{strDir}{"Total"}[0]=0;
opendir(DIR,$strDir) or die "$!\n";
my @files = grep (/[^\.]/,readdir(DIR));
closedir( DIR );
foreach $nomFic (@files) {
my $nomComplet = $strDir."\\".$nomFic;
if (-d $nomComplet){
recupPages ($nomComplet);
$tabRep{$strDir}{"Total"}[0] += $tabRep{$nomComplet}{"Total"}[0];
}
else{
my $cptTotal = 0;
my $cptCode = 0;
my $cptCommentaire = 0;
my $strligne;
if($nomFic !~
/(doc$)|(rtf$)|(xls$)|(pps$)|(ppt$)|(eml$)|(txt$)|(vss$)|(zip$)|(pdf$)/i )
{
$i++;
open(PL,"$nomComplet") or die "$!\n";
my @lines=<PL>;
foreach $strligne (@lines){
chomp ($strligne);
$cptTotal++;
}
close(PL);
$tabRep{$strDir}{"Total"}[0] += $cptTotal;
$tabRep{$strDir}{$nomFic}[0] = $cptTotal;
}
}
}
}



sub listePages{
my $strDir=$toto->get();
my $ext1=$toto1->get();
recupPages($strDir,0);
open SORTIE,"> $ext1";
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my $dateUs = $mday."/".($mon+1)."/".(1900+$year);
my $rep;
my $fic;
my $bi=$i;
my $lgmax = 0;
print SORTIE "Nbre fichiers en date du $dateUs
\n************************************\n\nPour $bi fichiers réparties
ainsi:\n";
foreach $rep (sort keys (%tabRep)){
my $itot = 0;
my %tabTmp = %{$tabRep{$rep}};
print SORTIE "\nNom du Dossier $rep
\n*********************************************\n\n";
foreach $fic (sort keys %tabTmp){
$lgmax = (length($fic) > $lgmax) ? length($fic) : $lgmax;
my @totot = @{$tabTmp{$fic}};
if ($fic eq "Total"){
$itot = $totot[0];
}
else {
my $padded = sprintf("%-${lgmax}s", $fic);
print SORTIE "$padded \t\n";
}
}
}
close(SORTIE);
}

Réponses