Tags: perl

Sort by: Date / Title /

  1. 2 months ago by spirit
    1. # Synopisis: following error while installing any perl package with CPAN
    2.  
    3. # Looks good
    4. # Writing Makefile for Package
    5. #     -- NOT OK
    6. # Running make test
    7. #   Can't test without successful make
    8. # Running make install
    9. #   make had returned bad status, install seems impossible
    10.  
    11. # Solution: set make to /usr/bin/make in CPAN configuration
    12. $ cpan
    13. cpan> o conf make /usr/bin/make
  2. 9 months ago by toff
    Utilisation de INET_ATON de MySQL pour trier sur les IP
    1. #!/usr/bin/perl -w
    2. use strict;
    3. use warnings;
    4. use DBI;
    5.  
    6. #Connection à la base de donnes OCS
    7. my $dns = 'dbi:mysql:ocsweb:localhost';
    8. my $login = 'root';
    9. my $passwd = 'secret';
    10. my $dbh = DBI->connect($dns, $login, $passwd) or die "Connection impossible: $DBI::errstr\n";
    11.  
    12. # Recuperation des IP et des MAC  des postes SANS "Anti-virus"
    13. my $query = "SELECT DISTINCT hard.NAME, net.IPADDRESS, net.MACADDR ".
    14.                 "FROM softwares AS soft, hardware AS hard, networks AS net ".
    15.                 "WHERE hard.ID = soft.HARDWARE_ID ".
    16.                   "AND hard.ID = net.HARDWARE_ID ".
    17.                   "AND net.STATUS = 'up' ".
    18.                   "AND soft.name NOT LIKE '%anti-virus%' ".
    19.                 "ORDER BY INET_ATON(net.IPADDRESS) ";
    20.  
    21. my $result = $dbh->prepare($query) or die "Preparation impossible: $DBI::errstr\n";
    22.  
    23. $result->execute() or die "Execution impossible: $DBI::errstr\n";
    24.  
    25. #$result->dump_results();
    26.  
    27. printf ("Il y a %d correspondances:\n",$result->rows);
    28.  
    29. while ( my ($name, $ip, $mac) = $result->fetchrow_array()){
    30.         print "$name, \t$ip, \t$mac\n";
    31. }
    32. $result->finish();
    33. $dbh->disconnect();
  3. 9 months ago by sebclick
    Vim peut indenter automatiquement du code source (c, java, ...)
    
    Sélectionner la partie du code source à traiter en mode visuel (v)
    Appuyer sur la touche =
  4. 9 months ago by griffith
    1. # mode interactif
    2. perl -MCPAN -e shell
    3.  
    4. # installation directe
    5. perl -MCPAN -e 'install MODULE'
  5. 10 months ago by henri
    1. while($addr !~ /^([O1]?\d\d?|2[0-4]\d|25[0-5])\.([O1]?\d\d?|2[0-4]\d|25[0-5])\.([O1]?\d\d?|2[0-4]\d|25[0-5])\.([O1]?\d\d?|2[0-4]\d|25[0-5])$/){
    2.                 print "Please give the IP address of the remote server:\n";
    3.                 $addr = get_answer();
    4.         }
  6. 10 months ago by celos
    1. #!/usr/bin/perl
    2. #
    3. # It's my first script in Perl, so be lenient.
    4. #
    5. # This script works only for TV shows and their subtitles !
    6. # When you want to see your favorite tv show, with its sub, you launch the video
    7. # with your favorite video player, and you add the path of the subtitles.
    8. # Many video players, like mplayer, import automatically the subtitles if they
    9. # have the same name. This script renames the subtitles files (.srt) of a directory
    10. # exactly like the corresponding videos (.avi).
    11. # You won't need to specify the path of the subtitles to your video player anymore.
    12. #
    13. # Example:
    14. # Video: my_video.s04e38.something.dot.something_else.avi
    15. # Subtitle file: video.438.srt
    16. # After running the script, the subtitle will be named:
    17. # my_video.s04e38.something.dot.something_else.srt
    18. #
    19. # The formats supported by the script:
    20. # - sAAeBB or SAAEBB with AA the season and BB the episode.
    21. # - ABB with A the season and BB the episode.
    22. # - AxBB with A the season and BB the episode.
    23. #
    24. # If the script is launched without any arguments, then the videos and subtitles
    25. # directories will be set to the current directory.
    26. #
    27. # Options:
    28. #       
    29. #       -h print command list
    30. #
    31. # -d (-dir) <videos directory>
    32. # Specify the directory where the videos are located.
    33. # If this option is not set, the video directory will be the current directory.
    34. #
    35. # -s (-sub) <subtitles files directory>
    36. # Specify the directory of the subtitles files.
    37. # If this option is not set, the subtitles directory will be the same directory as
    38. # the videos directory. Which means that if the videos directory is not set, it will be
    39. # the current directory.
    40. #
    41. # -p (--preview)  <without arguments>
    42. # Preview mode. If this options is set, the subtiles new names will be display on the
    43. # screen without being renamed.
    44. #
    45. # I hope this script will be as useful as it's to me.
    46. #
    47. # Enjoy your tv shows ;-)
    48. #
    49.  
    50. use Cwd;
    51. #use Getopt::Std;
    52. use Getopt::Long;
    53.  
    54. my $preview = 0;
    55. my $help = 0;
    56. GetOptions( "dir=s" => \$dir, "sub=s" => \$sub, "preview!" => \$preview, "help!" =>\$help ) or printOptions();
    57.  
    58. if ($help == 1){
    59.   print "Command list\n";
    60.   printOptions();
    61. }
    62.  
    63.  
    64. if ($preview == 1) {print "****** PREVIEW MODE ******\n";}
    65. else {print "****** RENAME MODE *******\n";}
    66.  
    67. chomp ($currentDir = getcwd());
    68. my $videoDir = $currentDir;
    69. my $subDir = $currentDir;
    70.  
    71. if (defined $dir){
    72.   $videoDir = $dir;
    73. }
    74. print "dir: $videoDir\n";
    75.  
    76. if (defined $sub) {
    77.         $subDir = $sub;
    78. }
    79. else {
    80.         $subDir = $videoDir;
    81. }
    82.  
    83. opendir(DIR, $videoDir) || die "can't opendir $videoDir: $!";
    84. while (my $path = readdir(DIR)) {
    85.         push(@videosList, $path) if $path =~ m/\.avi$/;
    86. }
    87. closedir(DIR);
    88.  
    89. if (!@videosList){
    90.         print"\n No videos found ! check your path !\n";
    91.         exit();
    92. }
    93.  
    94. $temp = getcwd();
    95. opendir(DIR, $subDir) || die "can't opendir $subDir: $!";
    96. while (my $path = readdir(DIR)) {
    97.         push(@subsList, $path) if $path =~ m/\.srt$/;
    98. }
    99. closedir(DIR);
    100.  
    101. if (!@subsList){
    102.         print "\n No subtitles found ! check your path !\n";
    103.         exit();
    104. }
    105.  
    106. if ($videoDir ne $currentDir){
    107.         chdir ($videoDir) || die "Can't cd to spool: $!\n";
    108. }
    109.  
    110. foreach $f (@videosList) {
    111.                
    112.         ################
    113.         # VIDEOS FILES #
    114.         ################
    115.        
    116.         my @result = getSeasonEpisod($f);
    117.         $season = @result[0];
    118.         $episod = @result[1];
    119.  
    120.         foreach $s (@subsList) {
    121.                
    122.                 if ($videoDir ne $subDir) {
    123.                         chdir ($currentDir) || die "Can't cd to spool: $!\n";
    124.                         chdir ($subDir) || die "Can't cd to spool: $!\n";
    125.                 }
    126.  
    127.                 ####################
    128.                 # SUBTITLES FILES  #
    129.                 ####################
    130.        
    131.                 my @result = getSeasonEpisod($s);
    132.                 $seasonSub = @result[0];
    133.                 $episodSub = @result[1];       
    134.  
    135.                 if ($season == $seasonSub and $episod == $episodSub){
    136.                         my ($vidName) = $f =~ m/(.*)\.avi$/;
    137.                         print "Rename: $s --> $vidName.srt";
    138.                         print "\n";
    139.                         if ($preview != 1){
    140.                                 rename($s,"$vidName.srt") || die "Cannot rename $s: $!";
    141.                         }
    142.                 }
    143.         }
    144. }
    145.  
    146. # get season and episode
    147. sub getSeasonEpisod {
    148.         my $season = 0;
    149.         my $episod = 0;
    150.  
    151.         # format ABB
    152.         if(@_[0] =~ /(\d)(\d\d)/){
    153.                 $season = $1;
    154.                 $episod = $2;
    155.         }
    156.  
    157.         # format sAAeBB
    158.         elsif (@_[0] =~ /[sS](\d\d)[eE](\d\d)/){
    159.                 $season = $1;
    160.                 $episod = $2;
    161.         }
    162.  
    163.         # format AxBB
    164.         elsif (@_[0] =~ /(\d)[xX](\d\d)/){
    165.                 $season = $1;
    166.                 $episod = $2;
    167.         }
    168.        
    169.         else { 
    170.                 print "Video format Not Match ! \n";
    171.         }
    172.        
    173.         return ($season,$episod);
    174. }
    175.  
    176. # print options
    177. sub printOptions(){
    178.   print "-h print command list\n";
    179.   print "-d (-dir) <videos directory>\n";
    180.   print "-s (-sub) <subtitles files directory>\n";
    181.   print "-p (--preview)  <without arguments>\n";
    182.   exit();
    183. }

First / Previous / Next / Last / Page 1 of 1 (6 posteets)