diff --git a/perl/essai3.perl b/perl/essai3.perl index 03f6f0d..ae67f5b 100755 --- a/perl/essai3.perl +++ b/perl/essai3.perl @@ -1,23 +1,28 @@ #!/usr/bin/perl +use 5.16.0; + # Exercices tableaux -@alphabet = ("a" .. "z"); -@cartes = ("01".."10","valet","dame","roi"); -@annee=("a1","a2","lp"); -@promo=@annee; -@tout = (@alphabet , "dut" , @cartes , 1145, "\n"); +my @alphabet = ("a" .. "z"); +my @cartes = ("01".."10","valet","dame","roi"); +my @annee=("a1","a2","lp"); +my @promo=@annee; +my @tout = (@alphabet , "trucmachin" , @cartes , 1145, "\n"); print @tout; # Autre exercice -@jours=("Lundi","Mardi","Mercredi"); +my @jours=("Lundi","Mardi","Mercredi"); -foreach $jours(@jours) -{ - print $jours."\n"; -} +# explicite +#foreach $jours(@jours) +#{ +# print $jours."\n"; +#} +say foreach @jours ; + # Perl : les nombres : < > <= >= == != # Chaînes : lt gt eq ne diff --git a/perl/grep.pl b/perl/grep.pl index 8e62e71..f61f87d 100755 --- a/perl/grep.pl +++ b/perl/grep.pl @@ -1,6 +1,4 @@ #!/usr/bin/perl -w -# -w pour les erreurs - $motif = shift(@ARGV); # $motif=$ARGV[0] #Shift @@ -8,14 +6,14 @@ $motif = shift(@ARGV); # Manière non explicite while(<>) { - if(/$motif/) { print ; }; + print if(/$motif/); }; # Manière explicite -while($ligne = <>) -{ - if($ligne =~ /$motif/) - { - print $ligne; - } -}; +#while($ligne = <>) +#{ +# if($ligne =~ /$motif/) +# { +# print $ligne; +# } +#}; diff --git a/perl/grep2.pl b/perl/grep2.pl index 059b7a0..cfbc973 100755 --- a/perl/grep2.pl +++ b/perl/grep2.pl @@ -6,9 +6,7 @@ foreach $f (@ARGV) { open(F,"<$f") || die "Impossible de lire le fichier $f : $!"; - while() - { - if(/$motif/) - { print "Motif trouvé dans $f : $_ \n";} + while() { + print "Motif trouvé dans $f : $_ \n" if(/$motif/); }; } diff --git a/perl/wc.pl b/perl/wc.pl index 680382e..ac647ff 100755 --- a/perl/wc.pl +++ b/perl/wc.pl @@ -5,10 +5,7 @@ open(F, "<$ARGV[0]") || die "Problème d'ouverture de fichier ! "; $i = 0 ; -while() -{ - $i++; -}; +$i++ while(); close(F);