Advertisement
KeplerBR

Transformar SQL em TXT - v 0.1

May 15th, 2013
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.67 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use feature qw(say);
  5.  
  6. # Definição das variáveis
  7. my (@txt, $commentBlock);
  8.  
  9. # Iniciar leitura do arquivos
  10. open(my $arq,'+<sql.sql') || die "$!\n";
  11.  
  12. while (<$arq>) {
  13.     chomp;
  14.    
  15.     $commentBlock = 1 if (substr($_, 0, 2) eq '/*');
  16.    
  17.     if ($_ ne '' && substr($_, 0, 2) ne '--' && !$commentBlock) {
  18.         my ($monster) = $_ =~ /REPLACE INTO `mob_db` VALUES\([0-9]*,'[a-zA-z]*','(.*)','/;
  19.         push (@txt, "$monster\n") if ($monster);
  20.     }
  21.    
  22.     $commentBlock = 0 if (substr($_, -2) eq '*/');
  23. }
  24.  
  25. close($arq);
  26.  
  27. # Salvar TXT
  28. open my $fileTXT,">". 'txtGerado.txt' or die "Cannot create file TXT: $!";
  29. print $fileTXT @txt;
  30. close $fileTXT;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement