http://www.google.com/notebook/feeds/05371167392778299650/notebooks/BDRRESwoQhIza5LYh2008-07-09T09:43:20.072ZMemo PerlpandelisGoogle Notebook6110http://www.google.com/notebook/feeds/05371167392778299650/notebooks/BDRRESwoQhIza5LYh/NDRkjSwoQgrrK0uch2006-10-24T12:36:44.418Z2008-07-09T09:43:20.072ZPasser des arguments use Getopt::Std; getopt("c"); $opt_c; Envoyer une com...<p><b>Passer des arguments </b><br>use Getopt::Std;<br>getopt(&quot;c&quot;);<br>$opt_c;<b><br><br>Envoyer une commande</b><br>`sed -i &quot;/FIN BLOC (PRESENTATION)/,/&lt;<a href="javascript:void(0);">\\/body</a>&gt;/d&quot; $i`;<br>$sortie=`anagram --bindict ¢¢E:/Anagram/words.bin ==¯¯ able`;<br>!!!Attention aux / qu&#39;il faut double slasher</p> <p><b>Faire du globbing </b><br>@fichiers = glob(&quot;*.htm&quot;);<br>perl -pi &#39;.bak&#39; -e &#39;s/&lt;.*?&gt;.*?&lt;\/.*?&gt;//&#39; K*.xml (il faut utiliser Cygwin car djbash a des pb de mémoire)</p> <p><b>Imprimer avec un 2 chiffres après la virgules </b><br>printf &quot;%s\t%.0f\t%.2f&quot;,&quot;$sub_num&quot;,&quot;$moy&quot;,&quot;$et&quot;;</p><pre style="font-family:arial,sans-serif"><font size="2"><b>Convertir un nombre en arrondi</b><br>$rounded = sprintf(&quot;%FORMATf&quot;, $unrounded);</font></pre><p><b>Remplacements en ligne de commande </b><br>perl -pi&#39;.bak&#39; -e &#39;s/&lt;.*?&gt;.*?&lt;\/.*?&gt;//&#39; K*.xml<br>perl -pi&#39;orig_*&#39; -e &#39;s/&lt;.*?&gt;.*?&lt;\/.*?&gt;//&#39; K*.xml<br>-p écrit les lignes<br>-n ne les écrit pas sans print</p><b>One-liners</b><p><a href="http://www.unixguide.net/unix/perl_oneliners.shtml">http://www.unixguide.net/unix/perl_oneliners.shtml</a> ==¯¯<br>N&#39;imprimer que si ça match<br>perl -i&#39;.bak&#39; -ne &#39;print &quot;$1\n&quot; if $_ =~ /(http.*rar)/ &#39; *.htm<br>who | perl -aF&quot;\t&quot; -lpe &#39;$_ = $F[0]&#39;<br>#!/usr/bin/perl<br>$\ = $/; # from -l<br>while (&lt;&gt;) { # from -p</p> <div>chomp; # from -l<br>@F = split; # from -a<br>$_ = $F[0]; # argument to -e<br>print; # from -p</div><a href=""></a> <p>} </p>pandelishttp://www.google.com/notebook/feeds/05371167392778299650/notebooks/BDRRESwoQhIza5LYh/NDSCRSgoQk7jW0uch2006-10-24T12:40:00.787Z2008-06-24T12:16:29.963ZChercher un package http://ppm.activestate.com/PPMPackages/zips/ Instal...<p><b>Chercher un package </b><br><a href="http://ppm.activestate.com/PPMPackages/zips/">http://ppm.activestate.com/PPMPackages/zips/</a> </p> <p><b>Installer un package à partir du dd (si il est dans C:) </b><br>Décompresser le zip, aller dans le dossier ou vous l&#39;avez décompressé<br>ppm install ¢¢c:/fichier.ppd ==¯¯</p><b>Installer / Utiliser PAR<br></b>Pour l&#39;installer, le télécharger sur activestate<br>J&#39;ai essayé install manuelle mais ça ne marche pas<br>pp -o hello.exe hello.pl <br><b><br>Arrondir un nombre<br></b>$b = sprintf(&quot;%.2f&quot;, $a);<br><b><br>Time a process<br></b>sub concord {$compte = 0;}<br>timethese(10, {concord =&gt; &#39;concord()&#39;});<br>This will measure the concord func ten times pandelishttp://www.google.com/notebook/feeds/05371167392778299650/notebooks/BDRRESwoQhIza5LYh/NDSUDSwoQwtHXhbch2006-05-26T12:40:37.826Z2008-04-03T15:06:05.561ZPAR http://articles.mongueurs.net/magazines/ Record Separator RS $/="" ...<p> <a href="http://par.perl.org/index.cgi">PAR</a><br> <a href="http://articles.mongueurs.net/magazines/">http://articles.mongueurs.net/magazines/</a><br> <b>Record Separator RS<br>$/=&quot;&quot;<br><br>Ouvrir un fichier unicode</b><br> open(FH, &quot;&lt; :encoding(UTF-8)&quot;, $_)<br><b>Ouvre et écrit en unicode</b><br>use open &#39;:utf8&#39;; <br></p><p> <b>Tranche de ligne (imprimer ou stocker)</b><br> print @F[1,3];<br> print @F[1 .. @F];<br>$ligne = &quot;@F[1 .. @F]&quot;;</p><p> <b> Format Mac </b><br> $/ = &quot;\x0d&quot;;</p><p> <b> Imprimer sur la sortie standard (entrée standard: STDIN) </b><br> print STDOUT &quot;bonjour&quot; </p><a href="http://www.google.com/notebook/static_files/blank_quirks.html"></a><p> <b> Selectionner une sortie </b><br> select LOG <br> print &quot;bonjour&quot;; </p><a href="http://www.google.com/notebook/static_files/blank_quirks.html"></a><p> <b> Parcourir un tableau </b><br> foreach $i (@a){} <br> for ($i=0;$i&lt;@a;$i++){ </p><a href="http://www.google.com/notebook/static_files/blank_quirks.html"></a><p> <b> Parcourir un hachage </b><br> foreach $i (keys %a){} <br> while (($key,$value) = each(%a){}<br><br><b>Nombre d&#39;entrées dans un hachage </b><br> $num_Cara = scalar keys %hach; <br></p><p><b>Parcourir toutes les lettres d&#39;une chaîne</b><br>@Lettres = split(&quot;&quot;,$F[0]);<br>for ($i=0;$i&lt;@Lettres;$i++){  }        <br><br> </p>pandelishttp://www.google.com/notebook/feeds/05371167392778299650/notebooks/BDRRESwoQhIza5LYh/NDSeRSgoQr-LX0Och2006-10-24T11:30:28.271Z2008-02-25T14:23:07.990ZRemplacer les accents français $F[$lem] =~ tr/éèêëàäâïîöôüûùçÀÂÄÇÈÉÊËÎÏÔ...<p> <b>Remplacer les accents français </b><br>$F[$lem] =~   tr/éèêëàäâïîöôüûùçÀÂÄÇÈÉÊËÎÏÔÖÙÛÜ/eeeeaaaiioouuucAAACEEEEIIOOUUU/;<br><b>Consonnes du français</b><br>BCDFGHJKLMNPQRSTVWXZÇ<br>bcdfghjklmnpqrstvwxzç<br></p><p><br><b>Enlever les accents du monde entier</b><br>tr/ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ/aaaaaaaaaaaaooooooooooooeeeeeeeecciiiiiiiiuuuuuuuuynn/;<br><b><br></b><b> Caractères hexadécimaux </b><br> s/\x0d//g;<br><b><br>Expression régulières minimales:</b> <br>* -&gt; *? <br>+ -&gt; +?<br><br><b> Remplacer du texte </b><br> $destination = $source; <br> $destination =~ s/ceci/cela/g;<br><br> <b> Remplacer &quot; chien &quot; par &quot;chien&quot; </b><br> $_ =~ s/ &quot; ([^&quot;]*) &quot; / &quot;$1&quot; /g</p><p> <b> Compter le nombre d&#39;occurences d&#39;un pattern </b><br> $nombre = ($F[0] =~ s/pat/pat/g); (sais pas si marche)<br> $count = @{[$string =~ /$match/g]}; (semble marcher)</p><p> <b> Extraire qq chose (un nombre) d&#39;une expression rationnelle </b><br> if ($_=~ /.*output.*:.*([0-9]{1,})/; $nboutput = $1;} <br> ($mot) = ($lines[$i+1] =~ /^(.*?)\t/);</p><b>Search for french words</b><br>s/^-//g;<br>s/\W\-//g;<br>while (/([àâéèêëîïôöùûüçÀÂÉÈÊËÎÏÔÖÙÛÜÇA-Za-z-]+)/g) {<br>print $1;}<br><b><br>Virer les caractères qui ne sont pas des lettres<br><span>s/^W//g;</span><br><br>Use french locale (on a french windows)<br></b>use locale;<b></b><br>pandelishttp://www.google.com/notebook/feeds/05371167392778299650/notebooks/BDRRESwoQhIza5LYh/NDSCRSgoQo76D0uch2006-10-24T12:17:21.699Z2007-09-19T09:54:11.836ZParcourir tous les fichier d'un dossier opendir(REP, "$ARGV[0]"); @list...<p> <strong> Parcourir tous les fichier d&#39;un dossier </strong><br> opendir(REP, &quot;$ARGV[0]&quot;);<br> @liste = grep { /.cnr$/ }readdir(REP);<br> for $file(@liste){ </p><div>open(INPUT,&quot;&lt;./$ARGV[0]/$file&quot;);<br> while(&lt;INPUT&gt;){</div> <p> <strong>Parcourir tous les fichiers d&#39;un dossier récursivement</strong><br> @ARGV = qw(.) unless @ARGV;<br> use File::Find;<br> find sub { </p><div>if ($File::Find::name =~ /.cha$/){<br> open(FH, &quot;&lt; :encoding(UTF-8)&quot;, $_)<br> while(&lt;FH&gt;){blabla}</div><p> }, @ARGV;<br><br><strong> Parcourir 2x le même fichier </strong><br> open(UN,&quot;&lt;$ARGV[0]&quot;); <br> while(&lt;UN&gt;){ <br> } <br> close(UN); <br> open(DEUX,&quot;&lt;$ARGV[1]&quot;); <br> while(&lt;DEUX&gt;){ <br> } <br> close(DEUX); </p><p> <strong> Ecrire dans un fichier particulier </strong><br> open(ABSTRACT,&quot;&gt;$abstract&quot;); <br> print ABSTRACT &quot;blabla&quot;;<br></p><p><strong>Changer l&#39;extension du fichier </strong><br>$nomfi=$ARGV[0]; <br>$nomfi=~s/\..*$//; <br>$nomdef=$nomfi.&quot;.def&quot;; </p><strong>Déplacer un fichier<br></strong>chdir(&quot;$ARGV[0]&quot;);<br>move(&quot;$file&quot;, &quot;..<a href="javascript:void(0);">\\fichierspb\\</a>$file&quot;);<br><br><strong>Aller à la prochaine ligne </strong><br>LINE:<br>while (&lt;&gt;) {next LINE;}<br><strong><br>Détecter la fin d&#39;un fichier<br></strong>if (eof()) {print &quot;C&#39;est la fin&quot;;}<br><br><b>Ecrire un fichier unix (linux)</b><br>$CRLF = &quot;\x0d\x0a&quot;;<br>print &quot;blabla&quot;; print &quot;$CRLF&quot;;<br><br><b>Copier des fichiers à un autre endroit<br></b>use File::Copy;<br>$newname = &quot;..\\temp\\&quot;.$newname ;<br>copy($nomfic, $newname);<br><b>Autre méthode (si ça marche pas)</b><br> $newfile = &quot;__autres.pays\\&quot;.$newname ;<br> system(&quot;move /Y $file2 $newfile&quot;); <br><br>  pandelishttp://www.google.com/notebook/feeds/05371167392778299650/notebooks/BDRRESwoQhIza5LYh/NDQsLQwoQzJKt34ci2007-02-01T06:08:41.804Z2007-02-17T16:33:45.388Z$,="\t"; $"="\t"; #" open(UN,"<$ARGV[0]"); while(<UN>){ chomp; @F=spl...$,=&quot;\t&quot;;<br>$&quot;=&quot;\t&quot;; #&quot;<br>open(UN,&quot;&lt;$ARGV[0]&quot;);<br>while(&lt;UN&gt;){<br>    chomp;<br>    @F=split(&quot;\t&quot;);<br>    if ($F[29] ne &quot;&quot;){print @F;print &quot;\n&quot;;}<br>    <br>}<br>close(UN);pandelis