diff --git a/perl/essai3.perl b/perl/essai3.perl new file mode 100755 index 0000000..9994fa1 --- /dev/null +++ b/perl/essai3.perl @@ -0,0 +1,21 @@ +#!/usr/bin/perl + +# Exercices tableaux +@alphabet = ("a" .. "z"); +@cartes = ("01".."10","valet","dame","roi"); +@annee=("a1","a2","lp"); +@promo=@annee; +@tout = (@alphabet , "trucmachin" , @cartes , 1145, "\n"); + +print @tout; + +# Autre exercice + +@jours=("Lundi","Mardi","Mercredi"); + +print $_."\n" foreach @jours ; + +# Perl : les nombres : < > <= >= == != +# Chaînes : lt gt eq ne + +# !~ et =~ sont des opérateurs d'appartenance diff --git a/perl/grep.pl b/perl/grep.pl new file mode 100755 index 0000000..53f4a46 --- /dev/null +++ b/perl/grep.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl -w + +$motif = shift(@ARGV); +# $motif=$ARGV[0] +#Shift + +# Manière non explicite +while(<>) +{ + print if(/$motif/); +}; + +# Manière explicite +#while($ligne = <>) +#{ +# if($ligne =~ /$motif/) +# { +# print $ligne; +# } +#}; diff --git a/perl/grep2.pl b/perl/grep2.pl new file mode 100755 index 0000000..47b16ef --- /dev/null +++ b/perl/grep2.pl @@ -0,0 +1,13 @@ +#!/usr/bin/perl + +$motif=$ARGV[0]; +shift; +foreach $f (@ARGV) +{ + open(F,"<$f") || die "Impossible de lire le fichier $f : $!"; + + while() + { + print "Motif trouvé dans $f : $_ \n" if(/$motif/); + }; +}