resolu
resolu
#!usr/bin/perl
@ARGV =($fic);
my $nbmots = 0;
my $nbcar = 0;
while ($fic = <>) {
@mots = split(/\s+/,$ligne);
foreach $mot (@mots) {
next if ($mot =~/^d+\.?\d+$/);
$mot =~s/[,.;:]$//; $nbmots ++;
$nbcar += length($mot);
}
}
print ("Nombre total de mots :$nbmots\n");
print ("Nombre total de caractères :$nbcar\n");
exit 0;
resolu
salut,
J'ai pondu ça si ca peut t'aider
bye
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 #!/usr/bin/perl use strict; use warnings; # si aucun fichier n'est spécifié die if (not @ARGV) { die "Pas de fichier spécifié\n"; } # declaration du fichier dans $file my $file = shift @ARGV; # verifie que $file existe if (not -e $file) { die "Le fichier '$file' n'existe pas.\n"; } my $nb_lignes; # nombre de lignes my $nb_mots; # nombre de mots my $nb_caracteres; # nombre de caracteres open FILE, $file; # ouverture du fichier en lecture seul while (my $buffer = <FILE>) { $nb_lignes++; my @mots = split /\s+/, $buffer; $nb_mots += scalar @mots; $nb_caracteres += length $buffer; } print "Le fichier contient: $nb_lignes lignes\n"; print "Le fichier contient: $nb_mots mots\n"; print "Le fichier contient: $nb_caracteres\n";
resolu
Partager