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("c");<br>$opt_c;<b><br><br>Envoyer une commande</b><br>`sed -i "/FIN
BLOC (PRESENTATION)/,/<<a href="javascript:void(0);">\\/body</a>>/d"
$i`;<br>$sortie=`anagram --bindict ¢¢E:/Anagram/words.bin ==¯¯
able`;<br>!!!Attention aux / qu'il faut double slasher</p>
<p><b>Faire du globbing </b><br>@fichiers =
glob("*.htm");<br>perl -pi '.bak' -e
's/<.*?>.*?<\/.*?>//' 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 "%s\t%.0f\t%.2f","$sub_num","$moy","$et";</p><pre style="font-family:arial,sans-serif"><font size="2"><b>Convertir un nombre en arrondi</b><br>$rounded = sprintf("%FORMATf", $unrounded);</font></pre><p><b>Remplacements en ligne de commande
</b><br>perl -pi'.bak' -e 's/<.*?>.*?<\/.*?>//' K*.xml<br>perl
-pi'orig_*' -e 's/<.*?>.*?<\/.*?>//' 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'imprimer que si ça match<br>perl -i'.bak' -ne 'print "$1\n" if $_ =~
/(http.*rar)/ ' *.htm<br>who | perl -aF"\t" -lpe '$_ =
$F[0]'<br>#!/usr/bin/perl<br>$\ = $/; # from -l<br>while (<>) { # 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'avez
décompressé<br>ppm install ¢¢c:/fichier.ppd ==¯¯</p><b>Installer / Utiliser PAR<br></b>Pour
l'installer, le télécharger sur activestate<br>J'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("%.2f", $a);<br><b><br>Time a process<br></b>sub concord {$compte
= 0;}<br>timethese(10, {concord => 'concord()'});<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>$/=""<br><br>Ouvrir un fichier unicode</b><br>
open(FH, "< :encoding(UTF-8)", $_)<br><b>Ouvre et écrit en unicode</b><br>use open ':utf8'; <br></p><p>
<b>Tranche de ligne (imprimer ou stocker)</b><br>
print @F[1,3];<br>
print @F[1 .. @F];<br>$ligne = "@F[1 .. @F]";</p><p>
<b> Format Mac </b><br>
$/ = "\x0d";</p><p>
<b> Imprimer sur la sortie standard (entrée standard: STDIN) </b><br>
print STDOUT "bonjour" </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 "bonjour"; </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<@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'entrées dans un hachage </b><br>
$num_Cara = scalar keys %hach; <br></p><p><b>Parcourir toutes les lettres d'une chaîne</b><br>@Lettres = split("",$F[0]);<br>for ($i=0;$i<@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>*
-> *? <br>+ -> +?<br><br><b> Remplacer du texte </b><br>
$destination = $source; <br>
$destination =~ s/ceci/cela/g;<br><br>
<b> Remplacer " chien " par "chien" </b><br>
$_ =~ s/ " ([^"]*) " / "$1" /g</p><p>
<b> Compter le nombre d'occurences d'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'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'un dossier </strong><br>
opendir(REP, "$ARGV[0]");<br>
@liste = grep { /.cnr$/ }readdir(REP);<br>
for $file(@liste){ </p><div>open(INPUT,"<./$ARGV[0]/$file");<br>
while(<INPUT>){</div>
<p>
<strong>Parcourir tous les fichiers d'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, "< :encoding(UTF-8)", $_)<br>
while(<FH>){blabla}</div><p>
}, @ARGV;<br><br><strong> Parcourir 2x le même fichier </strong><br>
open(UN,"<$ARGV[0]"); <br>
while(<UN>){ <br>
} <br>
close(UN); <br>
open(DEUX,"<$ARGV[1]"); <br>
while(<DEUX>){ <br>
} <br>
close(DEUX); </p><p>
<strong> Ecrire dans un fichier particulier </strong><br>
open(ABSTRACT,">$abstract"); <br>
print ABSTRACT "blabla";<br></p><p><strong>Changer l'extension du fichier
</strong><br>$nomfi=$ARGV[0]; <br>$nomfi=~s/\..*$//;
<br>$nomdef=$nomfi.".def"; </p><strong>Déplacer un fichier<br></strong>chdir("$ARGV[0]");<br>move("$file", "..<a href="javascript:void(0);">\\fichierspb\\</a>$file");<br><br><strong>Aller à la prochaine ligne
</strong><br>LINE:<br>while (<>) {next LINE;}<br><strong><br>Détecter la fin d'un fichier<br></strong>if
(eof()) {print "C'est la fin";}<br><br><b>Ecrire un fichier unix (linux)</b><br>$CRLF = "\x0d\x0a";<br>print "blabla"; print "$CRLF";<br><br><b>Copier des fichiers à un autre endroit<br></b>use File::Copy;<br>$newname = "..\\temp\\".$newname ;<br>copy($nomfic, $newname);<br><b>Autre méthode (si ça marche pas)</b><br> $newfile = "__autres.pays\\".$newname ;<br> system("move /Y $file2 $newfile"); <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...$,="\t";<br>$"="\t"; #"<br>open(UN,"<$ARGV[0]");<br>while(<UN>){<br> chomp;<br> @F=split("\t");<br> if ($F[29] ne ""){print @F;print "\n";}<br> <br>}<br>close(UN);pandelis