[150] | 1 | % $Id$ |
---|
| 2 | |
---|
[152] | 3 | \section{Variables} |
---|
| 4 | |
---|
[153] | 5 | \subsection{Variables de Perl} |
---|
| 6 | |
---|
[152] | 7 | \begin{frame} |
---|
| 8 | \frametitle{types de variables} |
---|
| 9 | \textbf{15} types de variables: |
---|
| 10 | \pause |
---|
[170] | 11 | \begin{itemize} |
---|
| 12 | \item scalaires (scalar) |
---|
[152] | 13 | \pause |
---|
[170] | 14 | \item tableaux (array) |
---|
[152] | 15 | \pause |
---|
[170] | 16 | \item hash (hash) |
---|
[152] | 17 | \pause |
---|
[170] | 18 | \end{itemize} |
---|
[152] | 19 | \vfill |
---|
[170] | 20 | \onslide<2-> |
---|
| 21 | \includegraphics[height=40mm]{Angel_fish} |
---|
| 22 | \onslide<3-> |
---|
| 23 | \includegraphics[height=40mm]{tableau} |
---|
| 24 | \onslide<4-> |
---|
| 25 | \includegraphics[height=40mm]{hache} |
---|
| 26 | \onslide<5-> |
---|
| 27 | \vfill |
---|
[152] | 28 | Et les autres on s'en moque... |
---|
| 29 | \end{frame} |
---|
| 30 | |
---|
[153] | 31 | \subsection{Scalaire} |
---|
| 32 | |
---|
[152] | 33 | \begin{frame}[fragile] |
---|
| 34 | \frametitle{scalaire} |
---|
[170] | 35 | \begin{block}{Un \textbf{scalaire} est une simple valeur:} |
---|
| 36 | \begin{itemize} |
---|
[152] | 37 | \pause |
---|
| 38 | \item \emph{undef} |
---|
| 39 | \pause |
---|
| 40 | \item définie: |
---|
| 41 | \begin{itemize} |
---|
| 42 | \item un chiffre, nombre |
---|
| 43 | \item une chaine de caractères |
---|
| 44 | \item \ldots |
---|
| 45 | \end{itemize} |
---|
| 46 | \end{itemize} |
---|
[170] | 47 | \end{block} |
---|
[152] | 48 | \pause |
---|
| 49 | \vfill |
---|
[170] | 50 | \begin{block}{Convertion} |
---|
| 51 | Perl évalue et converti les valeurs numériques au vol! |
---|
| 52 | \end{block} |
---|
| 53 | \pause |
---|
| 54 | \vfill |
---|
| 55 | |
---|
| 56 | \begin{exampleblock}{Exemple de valeur de scalaire} |
---|
[152] | 57 | \begin{verbatim} |
---|
| 58 | $rien = undef; |
---|
[170] | 59 | $chiffre = 42; $chaine = "1"; |
---|
[152] | 60 | print $chaine + $chiffre; |
---|
| 61 | print $chaine . $chiffre; |
---|
| 62 | \end{verbatim} |
---|
[170] | 63 | \end{exampleblock} |
---|
| 64 | \end{frame} |
---|
| 65 | |
---|
| 66 | \begin{frame}[fragile] |
---|
| 67 | \frametitle{Scalair: Vrai ou Faux ?} |
---|
| 68 | \begin{block}{} |
---|
| 69 | Valeur \textit{fausses}: \textit{undef}, 0, "0", "" |
---|
| 70 | |
---|
| 71 | Valeur \textit{vraies}: le reste: 1, "1", "un chien ?" |
---|
| 72 | \end{block} |
---|
[152] | 73 | \pause |
---|
| 74 | \vfill |
---|
| 75 | |
---|
[170] | 76 | \begin{exampleblock}{Exemple de test} |
---|
| 77 | \begin{verbatim} |
---|
| 78 | $valeur = "0"; |
---|
| 79 | if ($valeur) # faux, "0" => 0 |
---|
| 80 | if ($valeur == 0) # vrai "0" => 0 |
---|
| 81 | if ($valeur eq "") # faux, chaine non vide |
---|
| 82 | \end{verbatim} |
---|
| 83 | \end{exampleblock} |
---|
| 84 | \pause |
---|
| 85 | \vfill |
---|
| 86 | |
---|
| 87 | \begin{exampleblock}{0 but True} |
---|
| 88 | \begin{verbatim} |
---|
| 89 | $valeur = "0E0"; |
---|
| 90 | \end{verbatim} |
---|
| 91 | \end{exampleblock} |
---|
[152] | 92 | \end{frame} |
---|
| 93 | |
---|
[153] | 94 | \subsection{Les tableaux} |
---|
| 95 | |
---|
[152] | 96 | \begin{frame}[fragile] |
---|
[170] | 97 | \frametitle{Tableau (array)} |
---|
| 98 | \begin{block}{Les tableaux sont des piles de scalaires} |
---|
| 99 | \begin{verbatim} |
---|
| 100 | $valeur = 3; |
---|
| 101 | @tableau = ($valeur, "chaines"); |
---|
| 102 | \end{verbatim} |
---|
| 103 | \end{block} |
---|
[152] | 104 | \pause |
---|
| 105 | |
---|
| 106 | \vfill |
---|
[170] | 107 | \begin{block}{} |
---|
| 108 | Ils sont dynamiques, et a une seule dimension |
---|
| 109 | \end{block} |
---|
| 110 | \end{frame} |
---|
[152] | 111 | |
---|
[170] | 112 | \begin{frame}[fragile] |
---|
| 113 | \frametitle{Tableau: Exemples} |
---|
| 114 | \begin{exampleblock}{Utilisation:} |
---|
[152] | 115 | \begin{verbatim} |
---|
[170] | 116 | @tableau = (1, 2, 3); |
---|
[152] | 117 | $tableau[3] = 4; |
---|
| 118 | $tableau[-1]; # dernier élément |
---|
| 119 | \end{verbatim} |
---|
[170] | 120 | \end{exampleblock} |
---|
[152] | 121 | \pause |
---|
| 122 | \vfill |
---|
[170] | 123 | \begin{alertblock}{Attention au \$} |
---|
| 124 | \begin{verbatim} |
---|
| 125 | @tableau; |
---|
| 126 | $tableau[1]; |
---|
| 127 | \end{verbatim} |
---|
| 128 | \end{alertblock} |
---|
[152] | 129 | \pause |
---|
| 130 | \vfill |
---|
[170] | 131 | \begin{block}{} |
---|
[152] | 132 | Nombre d'éléments: \verb+scalar(@tableau)+ |
---|
| 133 | |
---|
| 134 | Dernier indice: \verb+$#tableau+ |
---|
[170] | 135 | \end{block} |
---|
| 136 | \pause |
---|
| 137 | \vfill |
---|
| 138 | \begin{block}{Les bouts du tableau} |
---|
| 139 | \begin{tabular}{rcl} |
---|
| 140 | shift <=&\verb+0$$$$$n+&<= push\\ |
---|
| 141 | unshift =>&\verb+0$$$$$n+&=> pop\\ |
---|
| 142 | \end{tabular} |
---|
| 143 | \end{block} |
---|
[152] | 144 | \end{frame} |
---|
| 145 | |
---|
[175] | 146 | \subsection{Les tables de hashage} |
---|
| 147 | |
---|
[152] | 148 | \begin{frame}[fragile] |
---|
| 149 | \frametitle{hash} |
---|
[170] | 150 | \begin{block}{tables de hashage} |
---|
[152] | 151 | Ce sont des tableaux indexés \verb+clef => valeur+. |
---|
| 152 | |
---|
| 153 | Ils sont dynamiques. |
---|
| 154 | |
---|
| 155 | \pause |
---|
| 156 | \begin{itemize} |
---|
| 157 | \item la clef est une valeur textuelle simple |
---|
| 158 | \item la valeur est un \textbf{scalaire} |
---|
| 159 | \item l'ordre des clefs n'est pas conservé !!! |
---|
| 160 | \end{itemize} |
---|
[170] | 161 | \end{block} |
---|
[152] | 162 | |
---|
[170] | 163 | \end{frame} |
---|
| 164 | \begin{frame}[fragile] |
---|
| 165 | \frametitle{hash: exemple} |
---|
| 166 | \begin{exampleblock}{Utiliser tableau de hashage:} |
---|
| 167 | \begin{verbatim} |
---|
| 168 | %hash = ( foo => "un" |
---|
| 169 | bar => 2 ); |
---|
| 170 | print $hash{'bar'}; |
---|
| 171 | $clef = 'clef'; $hash{$clef}; |
---|
| 172 | \end{verbatim} |
---|
| 173 | \end{exampleblock} |
---|
[152] | 174 | \pause |
---|
[170] | 175 | \vfill |
---|
| 176 | \begin{alertblock}{Attention au \$} |
---|
[152] | 177 | \begin{verbatim} |
---|
[170] | 178 | %hash; |
---|
| 179 | $hash{baz}; |
---|
[152] | 180 | \end{verbatim} |
---|
[170] | 181 | \end{alertblock} |
---|
| 182 | \vfill |
---|
[152] | 183 | \pause |
---|
[170] | 184 | \begin{block}{keys: renvois les clefs} |
---|
[152] | 185 | \begin{verbatim} |
---|
[170] | 186 | keys(%hash); |
---|
[152] | 187 | \end{verbatim} |
---|
[170] | 188 | \end{block} |
---|
[152] | 189 | |
---|
| 190 | \end{frame} |
---|
| 191 | |
---|
[154] | 192 | \subsection{Les listes} |
---|
| 193 | |
---|
[152] | 194 | \begin{frame}[fragile] |
---|
| 195 | \frametitle{Comprendre les listes} |
---|
[170] | 196 | \begin{alertblock}{Perl aplati les listes !} |
---|
[152] | 197 | |
---|
| 198 | Le concept est simple, mais redoutable: |
---|
[170] | 199 | \end{alertblock} |
---|
[152] | 200 | \pause |
---|
| 201 | |
---|
[179] | 202 | \vfill |
---|
| 203 | \vfill |
---|
| 204 | \begin{exampleblock}{Prenons deux tableaux de trois entrées:} |
---|
[152] | 205 | \begin{verbatim} |
---|
| 206 | @tab1 = (1, 2, 3); |
---|
| 207 | @tab2 = (4, 5, 6); |
---|
| 208 | \end{verbatim} |
---|
[179] | 209 | \end{exampleblock} |
---|
| 210 | \vfill |
---|
[152] | 211 | \pause |
---|
| 212 | |
---|
[179] | 213 | \begin{exampleblock}{} |
---|
| 214 | \begin{semiverbatim} |
---|
| 215 | (\only<6>{undef, }$un\only<4->{, @reste}) = \only<5->{(}@tab1\only<5->{, @tab2)}; |
---|
| 216 | \end{semiverbatim} |
---|
| 217 | \end{exampleblock} |
---|
| 218 | \begin{block}{} |
---|
| 219 | \only<3>{On copie la première entrée du tableau dans \$un} |
---|
| 220 | \only<4>{pareil, mais la fin du tableaux va dans @reste} |
---|
| 221 | \only<5>{@tab1 et @tab2 ne forme plus qu'un lors de la copie} |
---|
| 222 | \only<6>{la première entrée est ignoré (undef)} |
---|
| 223 | \end{block} |
---|
[152] | 224 | \end{frame} |
---|
| 225 | |
---|
| 226 | \begin{frame}[fragile] |
---|
| 227 | \frametitle{Comprendre les listes: les hash} |
---|
[170] | 228 | \begin{block}{} |
---|
[152] | 229 | '\verb+=>+' est un séparateur comme la '\verb+,+', donc c'est une liste: |
---|
| 230 | \begin{verbatim} |
---|
| 231 | %hash = (un => 1, deux => 2); |
---|
| 232 | %hash = (un, 1, deux, 2); |
---|
[170] | 233 | @tab = %hash; %hash = @tableau; |
---|
[152] | 234 | \end{verbatim} |
---|
[170] | 235 | \verb+@tab+ contient "un", 1\ldots |
---|
| 236 | \end{block} |
---|
[152] | 237 | \pause |
---|
[170] | 238 | \begin{block}{hash vers hash} |
---|
[152] | 239 | \begin{verbatim} |
---|
[153] | 240 | %unhash = (%hash2, %hash3); |
---|
[152] | 241 | \end{verbatim} |
---|
| 242 | \verb+%hash+ contient 1 \verb+=>+ 2, 3 \verb+=>+ 4\ldots |
---|
[170] | 243 | \end{block} |
---|
| 244 | \pause |
---|
| 245 | \begin{alertblock}{} |
---|
| 246 | Les clefs dupliquées sont ecrasées, la dernière gagne ! |
---|
| 247 | \end{alertblock} |
---|
[152] | 248 | \end{frame} |
---|
| 249 | |
---|
[165] | 250 | \subsection{les variables magiques} |
---|
| 251 | |
---|
| 252 | \begin{frame}[fragile] |
---|
[170] | 253 | \begin{block}{Elles existent dans tout programme perl.} |
---|
| 254 | Les principales à connaitre:\\ |
---|
[165] | 255 | \pause |
---|
| 256 | \vfill |
---|
| 257 | |
---|
| 258 | \begin{tabular}{ll} |
---|
| 259 | \verb+$_+&stockage par défaut\\ |
---|
| 260 | \pause |
---|
| 261 | \verb+@_+¶mètres des subroutines\\ |
---|
| 262 | \pause |
---|
| 263 | &\\ |
---|
| 264 | \verb+@ARGV+&les arguments passés aux programmes\\ |
---|
| 265 | \pause |
---|
| 266 | &\\ |
---|
| 267 | \verb+$a+ et \verb+$b+&utilisé par sort\\ |
---|
| 268 | \end{tabular} |
---|
[170] | 269 | \end{block} |
---|
[165] | 270 | \pause |
---|
| 271 | |
---|
| 272 | \vfill |
---|
| 273 | \vfill |
---|
| 274 | \begin{alertblock}{Attention à \$\_} |
---|
| 275 | \verb+$_+ permet d'écrire du code succin, mais n'augmente pas la visibilité: |
---|
| 276 | \begin{verbatim} |
---|
| 277 | $entier = int; |
---|
| 278 | \end{verbatim} |
---|
| 279 | \end{alertblock} |
---|
| 280 | \end{frame} |
---|