Вы находитесь на странице: 1из 18

Programmation PERL

Cours n1

Nassim ZELLAL
2012/2013

Perl - gnralits

Perl est un langage de programmation cr par Larry Wall en 1987.

Langage de programmation procdurale particulirement adapt au


traitement des donnes textuelles.

Langage interprt, il n'y a pas de phase intermdiaire de


compilation car l'interprteur, qui sappelle perl en minuscules
compile le code sans que le programmeur ne s'en rende compte
puis, il l'excute.

Mon premier script PERL

Ouvrir un diteur de texte (Notepad++).


crire dans un fichier (test.pl) ce qui suit :

#!/usr/bin/perl
print "Je suis tudiant en informatique ! \n";
Pour lexcuter, ouvrir une invite de commandes et lancer le script
perl :
perl test.pl

Mon deuxime script PERL (passage des paramtres


avec la variable spciale $ARGV[x])
crire dans un fichier (test2.pl) ce qui suit :

#!/usr/bin/perl
print "Je suis tudiant en $ARGV[0] et je mappelle
$ARGV[1]! \n";
Pour lexcuter, ouvrir une invite de commandes et lancer le script
perl :
perl test2.pl

Commentaires en PERL

crire dans un fichier (test3.pl) ce qui suit :

# ceci est un commentaire


print "Coucou !\n"
Pour lexcuter, ouvrir une invite de commandes et lancer le script
perl :
perl test3.pl
Remarque : raccourci sous Notepad++ : Ctrl + q (valable aussi
pour les commentaires multilignes)

Trois types de variables en PERL

Scalaire

Tableau

Tableau associatif (table de hachage)

Nommage des variables

lettres (minuscules ou majuscules, ASCII de prfrence)


Chiffres
_ (tiret bas)
prcd de $, @ ou %
Exemples :
$maChaine
$MaChaine2
$Ma_2eme_Chaine
$2eme_chaine
$ma chaine 2
$ma-chaine

Affectation dune valeur une variable

variable = valeur
Exemples :
$machaine = "toto";
$monnombre = 33;
@maliste = ('toto', 'titi');
%notes = ("cours1", 15, "cours2", 18, "cours3", 11);

Perl - scalaires

Une variable de type scalaire est une :

chane de caractres

nombre

Perl - scalaires - chane de caractres

'Coucou !'
une chane littrale
"Coucou !"
'Coucou\n'
\n n'est pas interprt
"Coucou\n"
\n est interprt comme le retour la ligne
"tu es \"magnifique\"
chappement des "
"je veux utiliser un \\"
\ est interprt comme un caractre
spcial "d'chappement (dspcialisation) "

"" une chane vide

Perl - scalaires - comparaison de chanes de


caractres

. concatnation
x multiplication (de chane de caractres)
Oprateurs de comparaison :
eq galit => Retourne 1 si $x contient la chane "Bonjour", sinon 0
ne ingalit => Retourne 1 si $x est diffrente de "Toto", sinon 0
lt plus petit que (less than) => Retourne 1 si $x est infrieure
"Toto", sinon 0
gt plus grand que (greater than) => Retourne 1 si $x est suprieure
"Toto", sinon 0
le plus petit ou gal (less than or equal) => Retourne 1 si $x est
infrieure ou gale "Toto", sinon 0
ge plus grand ou gal (greater than or equal) => Retourne 1 si
$x est suprieure ou gale "Toto", sinon 0

Perl - scalaires - oprations sur les chanes de


caractres

Operations :

"mon"." "."chien" => "mon chien"

"a"x3 => "aaa"

Perl - scalaires - oprations sur les nombres

$a = (1 + 2) * 3 - 4; # retourne 5 dans $a (rgle de priorit)


$a = 1 + 2 * 3 - 4; # retourne 3 dans $a (rgle de priorit)
$a= 8 - 4 - 2; retourne 2 et non 6 (rgle dassociativit)
$a = 7 / 8; # Divise 7 par 8 et met 0.875 dans $a
$a = 9 ** 10; # 9 la puissance 10
$a = 5 % 2; # le reste de 5 divis par 2 (modulo)
++$a; # retourne $a augment de 1 (pr-incrmentation)
$a++; # retourne $a avant de l'augmenter de 1 (postincrmentation)
--$a; # retourne $a diminu de 1
$a--; # retourne $a avant de le diminuer de 1

Perl - scalaires - comparaison de nombres

$a == $b # Retourne vrai si $a est gal $b


$a != $b # Retourne vrai si $a est diffrent de $b
$a > $b # Retourne vrai si $a est suprieur $b
$a < $b # Retourne vrai si $a est infrieur $b
$a >= $b # Retourne vrai si $a est suprieur ou gal $b
$a <= $b # Retourne vrai si $a est infrieur ou gal $b

Perl - oprateurs dassignement

$a = $b; # Assigne $b $a

$a += $b; # ajoute $b $a et met le rsultat dans $a

$a -= $b; # soustrait $b de $a et met le rsultat dans $a

$a .= $b; # ajoute la chaine $b la fin de $a

Perl - oprateurs logiques (boolens)

|| OU logique => Vrifie qu'une des conditions est ralise


((condition1)||(condition2))

&& ET logique => Vrifie que toutes les conditions sont ralises
((condition1)&&(condition2))

! NON logique => Inverse l'tat d'une variable boolenne (retourne


la valeur 1 si la variable vaut 0, 0 si elle vaut 1)
(!condition)
Remarque: depuis Perl5 une notation plus agrable existe :
or(au lieu de ||), and(au lieu de &&), not(au lieu de !)

Adresse de tlchargement de PERL

http://www.activestate.com/activeperl/downloads

Mon courriel

nassim_zellal@yahoo.fr

Вам также может понравиться

  • La programmation en GDS
    La programmation en GDS
    От Everand
    La programmation en GDS
    Оценок пока нет
  • LINUX Le Guide des commandes
    LINUX Le Guide des commandes
    От Everand
    LINUX Le Guide des commandes
    Оценок пока нет
  • TPVISCRIPT
    TPVISCRIPT
    Документ6 страниц
    TPVISCRIPT
    Karim Ghommam
    Оценок пока нет
  • TPVISCRIPT
    TPVISCRIPT
    Документ6 страниц
    TPVISCRIPT
    Karim Ghommam
    Оценок пока нет
  • Support de Cours PHP
    Support de Cours PHP
    Документ66 страниц
    Support de Cours PHP
    هداية مسلمة
    Оценок пока нет
  • Script-Shell 39 0
    Script-Shell 39 0
    Документ25 страниц
    Script-Shell 39 0
    Mcp Kassad
    Оценок пока нет
  • Chap2 Typevariable
    Chap2 Typevariable
    Документ20 страниц
    Chap2 Typevariable
    tlohm
    Оценок пока нет
  • Mon Premier Script VASS
    Mon Premier Script VASS
    Документ10 страниц
    Mon Premier Script VASS
    arapilatico
    Оценок пока нет
  • Chapitre 4 Langage de Programmation PHP
    Chapitre 4 Langage de Programmation PHP
    Документ66 страниц
    Chapitre 4 Langage de Programmation PHP
    Tray Oumayma
    Оценок пока нет
  • PHP
    PHP
    Документ57 страниц
    PHP
    Abdati Abdo
    Оценок пока нет
  • Shell IUT
    Shell IUT
    Документ70 страниц
    Shell IUT
    Julien Khalil
    Оценок пока нет
  • Corriges Exercices php5 Ed2
    Corriges Exercices php5 Ed2
    Документ176 страниц
    Corriges Exercices php5 Ed2
    rarhnouch
    100% (3)
  • Cours Linux Avancé CH4
    Cours Linux Avancé CH4
    Документ13 страниц
    Cours Linux Avancé CH4
    zakaria rouissiya
    Оценок пока нет
  • 1.PHP Mysql Partie1
    1.PHP Mysql Partie1
    Документ22 страницы
    1.PHP Mysql Partie1
    david koffi
    Оценок пока нет
  • Exercice S PHP 7
    Exercice S PHP 7
    Документ128 страниц
    Exercice S PHP 7
    Abdati Abdo
    Оценок пока нет
  • PHP - Part 1
    PHP - Part 1
    Документ41 страница
    PHP - Part 1
    ismail.zenati.1999
    Оценок пока нет
  • First Script
    First Script
    Документ6 страниц
    First Script
    Khaoula Trabelsi
    Оценок пока нет
  • Cours PHP
    Cours PHP
    Документ10 страниц
    Cours PHP
    Kaissane Said
    Оценок пока нет
  • M205 Support Cours V0 21 02 23
    M205 Support Cours V0 21 02 23
    Документ93 страницы
    M205 Support Cours V0 21 02 23
    Anas Amoury
    Оценок пока нет
  • Cours2 Développement Dapplication Web
    Cours2 Développement Dapplication Web
    Документ57 страниц
    Cours2 Développement Dapplication Web
    venanceharold
    Оценок пока нет
  • 1.3-Programmation Structurée en PHP
    1.3-Programmation Structurée en PHP
    Документ20 страниц
    1.3-Programmation Structurée en PHP
    Lady D
    Оценок пока нет
  • CPHP
    CPHP
    Документ34 страницы
    CPHP
    Kenza Sanaa
    Оценок пока нет
  • Chap2-Les Bases de La Programmation
    Chap2-Les Bases de La Programmation
    Документ95 страниц
    Chap2-Les Bases de La Programmation
    Binetta binette
    Оценок пока нет
  • PHP - Part 1
    PHP - Part 1
    Документ41 страница
    PHP - Part 1
    ismail.zenati.1999
    Оценок пока нет
  • 01-Scripts Shell
    01-Scripts Shell
    Документ8 страниц
    01-Scripts Shell
    Louazna Youssef
    Оценок пока нет
  • SE UNIX - Part2
    SE UNIX - Part2
    Документ31 страница
    SE UNIX - Part2
    simohamed.arrouch
    Оценок пока нет
  • Exercices - Corrigés by Dorsaf
    Exercices - Corrigés by Dorsaf
    Документ3 страницы
    Exercices - Corrigés by Dorsaf
    Gaith Belkacem
    Оценок пока нет
  • Partie5 PHP
    Partie5 PHP
    Документ49 страниц
    Partie5 PHP
    Rebecca
    Оценок пока нет
  • PHP
    PHP
    Документ78 страниц
    PHP
    hyouness012
    Оценок пока нет
  • Chap 6 - Programmation SHELL
    Chap 6 - Programmation SHELL
    Документ32 страницы
    Chap 6 - Programmation SHELL
    Abdel Adhim Chalouah
    Оценок пока нет
  • Langage PHP
    Langage PHP
    Документ144 страницы
    Langage PHP
    benmoussa
    Оценок пока нет
  • Java EE JSTL
    Java EE JSTL
    Документ19 страниц
    Java EE JSTL
    oreki chitanda
    Оценок пока нет
  • Chapitre Ii Variables, Constantes, Types Et Expressions
    Chapitre Ii Variables, Constantes, Types Et Expressions
    Документ13 страниц
    Chapitre Ii Variables, Constantes, Types Et Expressions
    Fabrice Djegoue
    Оценок пока нет
  • SYS1A1516-TP N°07
    SYS1A1516-TP N°07
    Документ7 страниц
    SYS1A1516-TP N°07
    Karim Karima
    Оценок пока нет
  • VI. Calcul Numérique Sur Les Entiers: El Mostafa DAOUDI-p. 252
    VI. Calcul Numérique Sur Les Entiers: El Mostafa DAOUDI-p. 252
    Документ51 страница
    VI. Calcul Numérique Sur Les Entiers: El Mostafa DAOUDI-p. 252
    Amine Ghayout
    Оценок пока нет
  • Scripte
    Scripte
    Документ3 страницы
    Scripte
    Jalal Tazi
    Оценок пока нет
  • Support PHP Mysql
    Support PHP Mysql
    Документ47 страниц
    Support PHP Mysql
    Teguebzanga Zida
    Оценок пока нет
  • Cours Gratuit - Com Id 2199
    Cours Gratuit - Com Id 2199
    Документ54 страницы
    Cours Gratuit - Com Id 2199
    Joshua Tchioffouo
    Оценок пока нет
  • Introduction Aux Scripts BASH
    Introduction Aux Scripts BASH
    Документ14 страниц
    Introduction Aux Scripts BASH
    freestyle113
    Оценок пока нет
  • Bioperl
    Bioperl
    Документ42 страницы
    Bioperl
    fdpdf31
    Оценок пока нет
  • Vous Dtes Logué Sous Le Compte Dupontj Le Répertoire Courant Est /usr/local/bin Et Nous Sommes Le Mercredi 08 Décembre 2021
    Vous Dtes Logué Sous Le Compte Dupontj Le Répertoire Courant Est /usr/local/bin Et Nous Sommes Le Mercredi 08 Décembre 2021
    Документ1 страница
    Vous Dtes Logué Sous Le Compte Dupontj Le Répertoire Courant Est /usr/local/bin Et Nous Sommes Le Mercredi 08 Décembre 2021
    kenza boufama
    Оценок пока нет
  • Leçon 3 - Variables Constantes Et Types
    Leçon 3 - Variables Constantes Et Types
    Документ6 страниц
    Leçon 3 - Variables Constantes Et Types
    kabdal
    Оценок пока нет
  • Ecriture de Scripts BASH - Jean Gourdin
    Ecriture de Scripts BASH - Jean Gourdin
    Документ13 страниц
    Ecriture de Scripts BASH - Jean Gourdin
    jaimeleloiret
    Оценок пока нет
  • Scripts
    Scripts
    Документ9 страниц
    Scripts
    Siwar Belhaj
    Оценок пока нет
  • PHP Mysql Abdali
    PHP Mysql Abdali
    Документ119 страниц
    PHP Mysql Abdali
    Mohammed Tesjale
    Оценок пока нет
  • TP PHP 1
    TP PHP 1
    Документ11 страниц
    TP PHP 1
    MoezBenRe
    Оценок пока нет
  • TP 3 2017 PHP Avec Solution 1
    TP 3 2017 PHP Avec Solution 1
    Документ6 страниц
    TP 3 2017 PHP Avec Solution 1
    Mohamed Mahjoub
    Оценок пока нет
  • Exos Corrigés Shell
    Exos Corrigés Shell
    Документ38 страниц
    Exos Corrigés Shell
    Mohamed Aziz EL HORR
    100% (1)
  • CH 4 PHP
    CH 4 PHP
    Документ70 страниц
    CH 4 PHP
    Chayma Ben Zekri
    Оценок пока нет
  • Les Scripts Shell
    Les Scripts Shell
    Документ12 страниц
    Les Scripts Shell
    samioutha
    100% (2)
  • Partie3 PHP
    Partie3 PHP
    Документ64 страницы
    Partie3 PHP
    ZINEB BELBACHIR
    Оценок пока нет
  • Chapitre II - Programmation Shell
    Chapitre II - Programmation Shell
    Документ15 страниц
    Chapitre II - Programmation Shell
    Jonathan
    Оценок пока нет
  • Atelier 105
    Atelier 105
    Документ9 страниц
    Atelier 105
    wael jouini14
    Оценок пока нет
  • PHPS5 PDF
    PHPS5 PDF
    Документ27 страниц
    PHPS5 PDF
    samira HAM
    Оценок пока нет
  • Cours PHP 10 11
    Cours PHP 10 11
    Документ45 страниц
    Cours PHP 10 11
    Oussama LS
    Оценок пока нет
  • Programmation Web: Partie 3: PHP
    Programmation Web: Partie 3: PHP
    Документ74 страницы
    Programmation Web: Partie 3: PHP
    Angélica DEKE
    Оценок пока нет
  • Chapitre3 TableauxEnPHP
    Chapitre3 TableauxEnPHP
    Документ9 страниц
    Chapitre3 TableauxEnPHP
    Firas Bahrini
    Оценок пока нет
  • S4 Blade
    S4 Blade
    Документ5 страниц
    S4 Blade
    bolmanesoukaina9
    Оценок пока нет
  • Corrige TP03
    Corrige TP03
    Документ3 страницы
    Corrige TP03
    Zidan Didi
    Оценок пока нет
  • TD PHP
    TD PHP
    Документ6 страниц
    TD PHP
    raflaur
    Оценок пока нет
  • Suites Adjacentes
    Suites Adjacentes
    Документ5 страниц
    Suites Adjacentes
    SalimDeepSide
    50% (2)
  • ch1 Systemenumeration
    ch1 Systemenumeration
    Документ31 страница
    ch1 Systemenumeration
    SalimDeepSide
    Оценок пока нет
  • Algebreboole
    Algebreboole
    Документ75 страниц
    Algebreboole
    SalimDeepSide
    Оценок пока нет
  • Serie Chocs
    Serie Chocs
    Документ4 страницы
    Serie Chocs
    aliali047742
    Оценок пока нет
  • Exam Ens
    Exam Ens
    Документ50 страниц
    Exam Ens
    SalimDeepSide
    100% (1)
  • Exercices - Algorithme
    Exercices - Algorithme
    Документ38 страниц
    Exercices - Algorithme
    N.NASRI Matlablog
    94% (49)
  • Conferences Du Professeur Omar Kihel
    Conferences Du Professeur Omar Kihel
    Документ1 страница
    Conferences Du Professeur Omar Kihel
    SalimDeepSide
    Оценок пока нет
  • Tuto Recensement MINESEC
    Tuto Recensement MINESEC
    Документ6 страниц
    Tuto Recensement MINESEC
    Boris Fouotsap
    Оценок пока нет
  • TP3 Table Requette
    TP3 Table Requette
    Документ6 страниц
    TP3 Table Requette
    kim
    100% (1)
  • Erp Sujets App CRCF
    Erp Sujets App CRCF
    Документ34 страницы
    Erp Sujets App CRCF
    samir
    100% (1)
  • Cirmaker Import.
    Cirmaker Import.
    Документ10 страниц
    Cirmaker Import.
    Jacquelin Silencieux
    Оценок пока нет
  • PowerPoint Cours Sur Les Integrales
    PowerPoint Cours Sur Les Integrales
    Документ26 страниц
    PowerPoint Cours Sur Les Integrales
    Manon Philippe
    Оценок пока нет
  • Mode Emploi HP Elite Book G 810
    Mode Emploi HP Elite Book G 810
    Документ83 страницы
    Mode Emploi HP Elite Book G 810
    olivier sax henin
    Оценок пока нет
  • S3L3 - Infrastructures À Cles Publiques
    S3L3 - Infrastructures À Cles Publiques
    Документ7 страниц
    S3L3 - Infrastructures À Cles Publiques
    ibou
    Оценок пока нет
  • Transcendants
    Transcendants
    Документ47 страниц
    Transcendants
    imad.elrhair7
    Оценок пока нет
  • Solution Informatique
    Solution Informatique
    Документ5 страниц
    Solution Informatique
    Delphisam
    Оценок пока нет
  • Rapport Arc Ics 2020
    Rapport Arc Ics 2020
    Документ27 страниц
    Rapport Arc Ics 2020
    Mohamed IFADA
    Оценок пока нет
  • Fiche Métier Administrateur Réseau
    Fiche Métier Administrateur Réseau
    Документ2 страницы
    Fiche Métier Administrateur Réseau
    Anicet Mbuyu Wa Ngoie
    Оценок пока нет
  • Le Lexique de La Blockchain
    Le Lexique de La Blockchain
    Документ2 страницы
    Le Lexique de La Blockchain
    Maria MEKLI
    Оценок пока нет
  • Rapport
    Rapport
    Документ11 страниц
    Rapport
    hafsia
    Оценок пока нет
  • L'ordinateur Et Ses Composants
    L'ordinateur Et Ses Composants
    Документ2 страницы
    L'ordinateur Et Ses Composants
    Imene Krichene
    Оценок пока нет
  • PROM - Option V18
    PROM - Option V18
    Документ38 страниц
    PROM - Option V18
    ENZO
    Оценок пока нет
  • Partiel H03sol
    Partiel H03sol
    Документ4 страницы
    Partiel H03sol
    oussama elkaissi
    Оценок пока нет
  • Manuel Factory I o
    Manuel Factory I o
    Документ30 страниц
    Manuel Factory I o
    Virgilio Mignardi
    Оценок пока нет
  • Régionale de Casa Settat
    Régionale de Casa Settat
    Документ2 страницы
    Régionale de Casa Settat
    Red Rose الوردة الاحمراء
    Оценок пока нет
  • Cours Gozim
    Cours Gozim
    Документ51 страница
    Cours Gozim
    khaled
    Оценок пока нет
  • Cours II - Aoutoul
    Cours II - Aoutoul
    Документ90 страниц
    Cours II - Aoutoul
    ZINEB AZ
    Оценок пока нет
  • EXCEL Cours 1
    EXCEL Cours 1
    Документ48 страниц
    EXCEL Cours 1
    Yassine Lahboubi
    Оценок пока нет
  • CAREL Regul-Présentation-K.air-FR
    CAREL Regul-Présentation-K.air-FR
    Документ58 страниц
    CAREL Regul-Présentation-K.air-FR
    Roger Akl
    Оценок пока нет
  • SL-D3000 Operation Guide FR
    SL-D3000 Operation Guide FR
    Документ159 страниц
    SL-D3000 Operation Guide FR
    philippe raynal
    Оценок пока нет
  • Code BGLOGIC Que J'ai Trouvé Utile - Page 3 - FR PDF
    Code BGLOGIC Que J'ai Trouvé Utile - Page 3 - FR PDF
    Документ20 страниц
    Code BGLOGIC Que J'ai Trouvé Utile - Page 3 - FR PDF
    Elzou Gamez
    Оценок пока нет
  • CCNA1
    CCNA1
    Документ264 страницы
    CCNA1
    Mohamed Amine Zouhri
    100% (1)
  • Supervision Réseau
    Supervision Réseau
    Документ21 страница
    Supervision Réseau
    Jin jørdän
    Оценок пока нет
  • Sujet de Preparation 13 Maths 2 Bac SM
    Sujet de Preparation 13 Maths 2 Bac SM
    Документ3 страницы
    Sujet de Preparation 13 Maths 2 Bac SM
    Hiba Ali
    Оценок пока нет
  • 4 - Domotique C'est Arrivé Demain
    4 - Domotique C'est Arrivé Demain
    Документ2 страницы
    4 - Domotique C'est Arrivé Demain
    5tocuatri
    Оценок пока нет
  • Manual Cisco Epc2425
    Manual Cisco Epc2425
    Документ108 страниц
    Manual Cisco Epc2425
    Anonymous 2lMI3jbZb
    Оценок пока нет
  • Traitement Automatique Des Langues: de L'extraction D'information Au Dialogue
    Traitement Automatique Des Langues: de L'extraction D'information Au Dialogue
    Документ8 страниц
    Traitement Automatique Des Langues: de L'extraction D'information Au Dialogue
    Noun Nouna
    Оценок пока нет