ajout de fichiers pour PERL -- notions intéressantes
This commit is contained in:
parent
d5c732de90
commit
e5d3b139cf
21
perl/essai3.perl
Executable file
21
perl/essai3.perl
Executable file
@ -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
|
20
perl/grep.pl
Executable file
20
perl/grep.pl
Executable file
@ -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;
|
||||
# }
|
||||
#};
|
13
perl/grep2.pl
Executable file
13
perl/grep2.pl
Executable file
@ -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(<F>)
|
||||
{
|
||||
print "Motif trouvé dans $f : $_ \n" if(/$motif/);
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user