From e5d3b139cfcd3b2da9bf2030b6856e7085015a90 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Thu, 5 Jan 2012 12:02:51 +0100 Subject: [PATCH] =?UTF-8?q?ajout=20de=20fichiers=20pour=20PERL=20--=20noti?= =?UTF-8?q?ons=20int=C3=A9ressantes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- perl/essai3.perl | 21 +++++++++++++++++++++ perl/grep.pl | 20 ++++++++++++++++++++ perl/grep2.pl | 13 +++++++++++++ 3 files changed, 54 insertions(+) create mode 100755 perl/essai3.perl create mode 100755 perl/grep.pl create mode 100755 perl/grep2.pl 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/); + }; +}