{"id":107,"date":"2004-07-07T11:54:06","date_gmt":"2004-07-07T09:54:06","guid":{"rendered":""},"modified":"2007-07-03T09:31:27","modified_gmt":"2007-07-03T07:31:27","slug":"perl-par-la-pratique","status":"publish","type":"post","link":"http:\/\/www.lookit.org\/blog\/?p=107","title":{"rendered":"Perl par la pratique"},"content":{"rendered":"<p>Petit tutorial PERL<br \/><!--more--><br \/><strong>COURS PERL :<\/strong><br \/>http:\/\/www.med.univ-rennes1.fr\/~poulique\/cours\/perl\/<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p>#!\/usr\/bin\/perl<br \/>#&nbsp; af &#8211; about files<\/p>\n<p>print &quot;Please enter file name &quot; if (-t STDIN);<br \/>chop ($&shy;&shy;&shy;&shy;&shy;&shy;name = &lt;STDIN&gt;);<\/p>\n<p>@fdata = stat($&shy;&shy;&shy;&shy;&shy;&shy;name);<br \/>@text = (&quot;device&quot;,&quot;inode&quot;,&quot;mode&quot;,&quot;links&quot;,<br \/>&nbsp;&quot;user id&quot;,<br \/>&nbsp;&quot;group id&quot;,&quot;device id&quot;,&quot;size&quot;, &quot;accessed&quot;,<br \/>&nbsp;&quot;modified&quot;,&quot;changed&quot;,&quot;blocksize&quot;,<br \/>&nbsp;&quot;block count&quot;);<\/p>\n<p>foreach $&shy;&shy;&shy;&shy;&shy;&shy;k(0..$&shy;&shy;&shy;&shy;&shy;&shy;#text) {<br \/>&nbsp;printf &quot;%-12s&quot;,$&shy;&shy;&shy;&shy;&shy;&shy;text[$&shy;&shy;&shy;&shy;&shy;&shy;k];<br \/>&nbsp;print $&shy;&shy;&shy;&shy;&shy;&shy;fdata[$&shy;&shy;&shy;&shy;&shy;&shy;k],&quot;n&quot;;<br \/>&nbsp;}<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>#!\/usr\/bin\/perl<br \/>use Archive::Tar;<br \/>use Net::FTP;<\/p>\n<p>$&shy;&shy;&shy;&shy;&shy;&shy;date=time();<br \/>my $&shy;&shy;&shy;&shy;&shy;&shy;ftp_html = <br \/>Net::FTP-&gt;new(&#39;server&#39;,Passive=&gt;1,Timeout=&gt;30000),&quot;n&quot;;<br \/>$&shy;&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;login(&#39;login&#39;,&#39;passwd&#39;);<\/p>\n<p>$&shy;&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;cwd(&#39;\/&#39;),&quot;n&quot;;<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my @fileList2 = $&shy;&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;ls(&#39;*.gz&#39;);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach my $&shy;&shy;&shy;&shy;&shy;&shy;file2 (@fileList2) {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $&shy;&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;delete($&shy;&shy;&shy;&shy;&shy;&shy;file2)<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/p>\n<p>$&shy;&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;cwd(&#39;\/CPNgroupe&#39;),&quot;n&quot;;<br \/>my @fileList = $&shy;&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;ls(&#39;*.bak&#39;);<br \/>foreach my $&shy;&shy;&shy;&shy;&shy;&shy;file (@fileList) {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $&shy;&shy;&shy;&shy;&shy;&shy;mois=&quot;2678400&quot;;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $&shy;&shy;&shy;&shy;&shy;&shy;datef=$&shy;&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;mdtm($&shy;&shy;&shy;&shy;&shy;&shy;file),&quot;n&quot;;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $&shy;&shy;&shy;&shy;&shy;&shy;sous= $&shy;&shy;&shy;&shy;&shy;&shy;date &#8211; $&shy;&shy;&shy;&shy;&shy;&shy;datef;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( $&shy;&shy;&shy;&shy;&shy;&shy;sous &gt; $&shy;&shy;&shy;&shy;&shy;&shy;mois ) {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $&shy;&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;delete($&shy;&shy;&shy;&shy;&shy;&shy;file);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>}<\/p>\n<p>$&shy;&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;quit;<br \/>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>$&shy;&shy;&shy;&shy;&shy;&shy;rep= &quot;\/test&quot; ;<br \/>opendir R, $&shy;&shy;&shy;&shy;&shy;&shy;rep or die &quot;impossible d&#39;ouvrir le r&eacute;p. $&shy;&shy;&shy;&shy;&shy;&shy;rep&quot;;<br \/>@liste=readdir(R);<br \/>foreach $&shy;&shy;&shy;&shy;&shy;&shy;f (@liste) {<br \/>&nbsp; next if $&shy;&shy;&shy;&shy;&shy;&shy;f eq &quot;.&quot; or $&shy;&shy;&shy;&shy;&shy;&shy;f eq &quot;..&quot;;<br \/>&nbsp; $&shy;&shy;&shy;&shy;&shy;&shy;file= &quot;$&shy;&shy;&shy;&shy;&shy;&shy;rep\/$&shy;&shy;&shy;&shy;&shy;&shy;f&quot;;<br \/>&nbsp; if (-f $&shy;&shy;&shy;&shy;&shy;&shy;file) {<br \/>&nbsp;&nbsp; (undef,undef,undef,undef,undef,undef,undef,$&shy;&shy;&shy;&shy;&shy;&shy;size,undef,$&shy;&shy;&shy;&shy;&shy;&shy;mtime)= <br \/>stat($&shy;&shy;&shy;&shy;&shy;&shy;file);<br \/>&nbsp; print &quot;$&shy;&shy;&shy;&shy;&shy;&shy;file $&shy;&shy;&shy;&shy;&shy;&shy;mtime $&shy;&shy;&shy;&shy;&shy;&shy;sizen&quot;;<br \/>&nbsp; $&shy;&shy;&shy;&shy;&shy;&shy;date=time();<br \/>&nbsp; $&shy;&shy;&shy;&shy;&shy;&shy;sous= $&shy;&shy;&shy;&shy;&shy;&shy;date &#8211; $&shy;&shy;&shy;&shy;&shy;&shy;mtime;<br \/>&nbsp; print &quot;$&shy;&shy;&shy;&shy;&shy;&shy;sous&quot;;<br \/>&nbsp; $&shy;&shy;&shy;&shy;&shy;&shy;huit= &quot;850&quot;;<br \/>&nbsp; if ( $&shy;&shy;&shy;&shy;&shy;&shy;sous &gt; $&shy;&shy;&shy;&shy;&shy;&shy;huit ) {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;OUAISSSS&quot;;<br \/>&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp; }<br \/>}<br \/>closedir R;<br \/>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>use Archive::Tar;<br \/>use File::DosGlob &#39;glob&#39;;<br \/>use Net::FTP;<\/p>\n<p>#my @fileList = $&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;ls(&#39;\/info\/*.gz&#39;);i<br \/>#$&shy;&shy;&shy;&shy;&shy;ftp_html = Net::FTP-&gt;new(&#39;server&#39;,Passive=&gt;1);<br \/>#$&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;login(logint&#39;,passwordc&#39;);<br \/>#$&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;binary();<br \/>#$&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;get(&quot;d:\/datap\/*.gz&quot;,&quot;1.gz&quot;);<br \/>#$&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;quit;<\/p>\n<p># $&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;get($&shy;&shy;&shy;&shy;&shy;file,fp\/$&shy;&shy;&shy;&shy;&shy;file&quot;);<br \/># $&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;get($&shy;&shy;&shy;&shy;&shy;file,&quot;\/datuipe\/$&shy;&shy;&shy;&shy;&shy;file&quot;);<br \/>#&nbsp;&nbsp;&nbsp; $&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;delete($&shy;&shy;&shy;&shy;&shy;file);<\/p>\n<p>#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my @fileList = $&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;ls(&#39;*.*&#39;);<br \/>#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach my $&shy;&shy;&shy;&shy;&shy;file (@fileList) {<br \/>#&nbsp;&nbsp;&nbsp;&nbsp; $&shy;&shy;&shy;&shy;&shy;test = $&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;mdtm($&shy;&shy;&shy;&shy;&shy;file);<br \/>#&nbsp;&nbsp;&nbsp; print &quot;$&shy;&shy;&shy;&shy;&shy;file&quot;;<br \/>#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/p>\n<p>my $&shy;&shy;&shy;&shy;&shy;ftp_html = Net::FTP-&gt;new(&#39;server&#39;,Passive=&gt;1);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;login(&#39;login&#39;,&#39;password&#39;);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;binary();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;cwd(&#39;\/ls&#39;),&quot;n&quot;;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;ls(&#39;*.*&#39;),&quot;n&quot;;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print $&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;ls(&#39;*.*&#39;),&quot;n&quot;;<br \/>$&shy;&shy;&shy;&shy;&shy;ftp_html-&gt;quit; <br \/>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>cd \/data\/<br \/>rm -fr *<\/p>\n<p>ncftp -u COMPTE -p &#39;PASSWORD&#39; SERVER &lt;&lt; TEST<br \/>bin<br \/>#set confirm-close no<br \/>cd test\/<br \/>get *.*<br \/>rm *.*<br \/>quit<br \/>TEST <br \/>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Petit tutorial PERL<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[8],"tags":[],"class_list":["post-107","post","type-post","status-publish","format-standard","hentry","category-informatique"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pWrTo-1J","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/www.lookit.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/107","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.lookit.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.lookit.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.lookit.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.lookit.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=107"}],"version-history":[{"count":0,"href":"http:\/\/www.lookit.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/107\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.lookit.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.lookit.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=107"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.lookit.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}