• Publicidad

Consulta sobre || y or

¿Apenas comienzas con Perl? En este foro podrás encontrar y hacer preguntas básicas de Perl con respuestas aptas a tu nivel.

Re: Consulta sobre || y or

Notapor pablgonz » 2012-01-17 16:31 @730

explorer escribiste:autodie mata el programa cuando ocurre un fallo en alguna de las funciones relacionadas con archivos. Y close() es una de ellas. Al llegar allí, se encuentra con que estás pretendiendo cerrar un archivo, que ya ha sido cerrado antes (posiblemente en la línea 335 y/o 460.
Justo lo que pensaste: cambié las formas de abrir los archivos, pero no puedo dar con la línea que abre FILE, el cual estoy cerrando en la 335... misma situación con la 460.

Con autodie me di cuenta que tenía un par de cosas demás (unos unlink() de sobra), pero ahora no puedo avanzar por el error de la línea 335.

En fin, seguiré depurando a ver qué puedo lograr.

Gracias por la información de los textos, veré si tienen alguno en la biblioteca de la universidad.
Saludos
pablgonz
Perlero nuevo
Perlero nuevo
 
Mensajes: 236
Registrado: 2010-09-08 21:03 @919
Ubicación: Concepción (Chile)

Publicidad

Re: Consulta sobre || y or

Notapor explorer » 2012-01-17 18:40 @819

Esto es lo que pasa:
  • haces los open() en las líneas 188 y 199
  • después, ejecutas RunFile(), en las líneas 193 y 208
  • RunFile, en la línea 366, lo primero que hace es llamar a searchTiKZ, en la 368
  • searchTiKZ, en la línea 284, hace un bucle while(<FILE>) en la 291, y el close de la 335
  • regresa el control a las líneas anteriores, y aparecen nuevos close en las líneas 195 y 221, y ahí sale el fallo, pues ya estaban cerrados en la 335.
En cuanto a la otra parte, la del open() de la 419, está bien, porque haces también el while() (línea 431) y el close() (línea 460), en la misma subrutina.
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Consulta sobre || y or

Notapor pablgonz » 2012-01-17 23:21 @015

Tienes toda la razón, he solucionado casi todo los problemas de open() y close(). En realidad tuve que agregar un par de open() (si estaba cerrado el archivo, era imposible cerrarlo de nuevo), te adjunto el código (me falta arreglar lo de clear, lo edito mañana), con esto solucioné los mensajes de error que me daba autodie (es más estricto que use strict; )
EDITADO (agregadas las correcciones).
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $argv:q'
  2.     if 0;
  3.  
  4. use strict;                            # to be sure, that all is safe ... :-)
  5.  
  6. # $Id: tikz2pdf.pl 2012-01-17 08:41:35Z Pablo $
  7. # v. 0.1   Extract tikzpicture, based on pst2pdf by Herbert Voss
  8. # 2012-01-17      (c) Pablo González Luengo
  9. # Thanks to Giuseppe Matarazzo
  10. # Couple to have the complete operation of the script, you need some software (Linux and Windows)
  11. # xpdf (needed to create EPS / PPM)
  12. # gnuplot (not necessary if not called from TiKZ)
  13. # pdftk (not necessary with the-pdftk)
  14. # ImageMagick (required if you want to create JPG / PNG or other format)
  15. #
  16. use File::Path;
  17. use File::Copy;
  18. use File::Basename;
  19. use IO::File;
  20. use Getopt::Long;
  21. use autodie;
  22.  
  23. #----------------------- User part begin ------------------------
  24. my $imageDir = "images";
  25. my $Iext     = ".pdf";                 # leave empty, if not a special one
  26. my $tempDir  = ".";                    # temporary directory
  27. my $verbose  = 1;                      # 0 or 1, logfile
  28. my $clear    = 0;                      # 0 or 1, clears all temporary files
  29. my $DPI      = 75;                     # very low value for the png's
  30. my $Iscale   = 1;                      # for \includegraphics
  31. my $noImages = 0;                      # 1->create no images
  32. my $force    = 0;                      # 1->force create images
  33. my $ppm      = 0;                      # 1->create .ppm files
  34. my $norun    = 0;                      # 1->runs pdflatex
  35. my $miktex   = 0;                      # 1->runs pdlatex for miktex
  36. my $eps      = 0;                      # 1->create .eps files
  37. my $ifiles   = 0;                      # 1->create image files .tex
  38. my $all      = 0;                      # 1->create all images and files for type
  39. my $nopdftk  = 0;                      # 1->create all images and files for type in force mode
  40.  
  41. #----------------------- User part end ---------------------------
  42. #----------------------- program identification, options and help
  43. my $program   = "tikz2pdf";
  44. my $ident     = '$Id: tikz2pdf.pl 2012-01-17 pablo $';
  45. my $copyright = <<END_COPYRIGHT ;
  46. Copyright 2012-01-17 (c) Pablo Gonzalez L <pablgonz\@yahoo.com>
  47. END_COPYRIGHT
  48. my $licensetxt = <<END_LICENSE ;
  49.     This program is free software; you can redistribute it and/or modify
  50.     it under the terms of the GNU General Public License as published by
  51.     the Free Software Foundation; either version 2 of the License, or
  52.     (at your option) any later version.
  53.  
  54.     This program is distributed in the hope that it will be useful, but
  55.     WITHOUT ANY WARRANTY; without even the implied warranty of
  56.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  57.     General Public License for more details.
  58.  
  59.     You should have received a copy of the GNU General Public License
  60.     along with this program; if not, write to the Free Software
  61.     Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  62.     MA  02111-1307  USA
  63. END_LICENSE
  64. my $title = "$program $ident\n";
  65. my $usage = <<"END_OF_USAGE";
  66. ${title}Usage: $program <texfile.tex>  [Options]
  67. tikz2pdf run a TeX source, and extract all TiKZ-related part as
  68.         single images  (pdf or eps or ppm, default pdf)
  69.         and then runs pdflatex. See tikz2pdf documentation for more info
  70. Options:
  71.   --help          - display this help and exit
  72.   --version       - display version information and exit
  73.   --license       - display license information and exit
  74.   --imageDir      - the dir for the created images (default images)
  75.   --DPI=<int>     - the dots per inch for a cretaed ppm files (default 75)
  76.   --ppm           - create .ppm files
  77.   --eps           - create .eps files  
  78.   --Iscale=<real> - the value for [scale=] in \\includegraphics
  79.   --noImages      - generate files without compile (need -norun)
  80.   --verbose       - creates long log
  81.   --clear         - delete all temp files
  82.   --norun         - create file-pdf.tex, but, no run pdflatex
  83.   --miktex        - for miktex users -enable-write18
  84.   --ifiles        - create images files (.tex) for all TiKZ enviroment
  85.   --force         - create images whitout pdftk.
  86.   --all           - create all image type and images.tex      
  87.   --nopdftk       - create all image type and images.tex in force mode
  88. Examples:
  89. * $program test.tex --all
  90. * produce test-pdf.tex and ppm,eps,tex and pdf for TiKZ-enviroment in image dir
  91. END_OF_USAGE
  92.  
  93. #
  94. my $result = GetOptions(
  95.     "help",
  96.     "version",
  97.     "license",
  98.     "DPI=i"      => \$DPI,             # numeric
  99.     "Iscale=f"   => \$Iscale,          # real
  100.     "imageDir=s" => \$imageDir,        # string
  101.     "tempDir=s"  => \$tempDir,         # string
  102.     "Iext=s"     => \$Iext,            # string
  103.     "clear"      => \$clear,           # flag
  104.     "noImages"   => \$noImages,        # flag
  105.     "force"      => \$force,           # flag
  106.     "ppm"        => \$ppm,             # flag
  107.     "norun"      => \$norun,           # flag
  108.     "miktex"     => \$miktex,          # flag
  109.     "eps"        => \$eps,             # flag
  110.     "ifiles"     => \$ifiles,          # flag
  111.     "all"        => \$all,             # flag
  112.     "nopdftk"    => \$nopdftk,         # flag
  113.     "verbose"    => \$verbose,
  114. ) or die $usage;
  115.  
  116. # help functions
  117. sub errorUsage { die "Error: @_ (try --help for more information)\n"; }
  118.  
  119. # options for command line
  120. if ($::opt_help) {
  121.     print $usage;
  122.     exit(0);
  123. }
  124. if ($::opt_version) {
  125.     print $title;
  126.     print $copyright;
  127.     exit(0);
  128. }
  129. if ($::opt_license) {
  130.     print $licensetxt;
  131.     exit(0);
  132. }
  133.  
  134. # open file
  135. my $InputFilename = "";
  136. @ARGV > 0 or errorUsage "Input filename missing";
  137. @ARGV < 2 or errorUsage "Unknown option or too many input files";
  138. $InputFilename = $ARGV[0];
  139.  
  140. # end open file
  141. my @SuffixList = ( ".tex", "", ".ltx" );    # possible extensions
  142. my ( $name, $path, $ext ) = fileparse( $ARGV[0], @SuffixList );
  143. if ( $ext eq "" ) { $ext = ".tex"; }   # me need the extension as well
  144. my $TeXfile = "$path$name$ext";
  145. my $Logfile = "$tempDir/$name.plog";   # our own log file
  146. open( LOGfile, ">$Logfile" );
  147. LOG("Parameters:");
  148. LOG("==> imageDir = $imageDir");
  149. LOG("==> Iext     = $Iext");
  150. LOG("==> DPI      = $DPI");
  151. LOG("==> Iscale   = $Iscale");
  152. LOG("==> tempDir  = $tempDir");
  153. LOG("==> verbose  = $verbose");
  154. LOG("==> clear    = $clear");
  155. LOG("==> noImages = $noImages");
  156. LOG("==> force    = $force");
  157. LOG("==> ppm      = $ppm");
  158. LOG("==> norun    = $norun");
  159. LOG("==> miktex   = $miktex");
  160. LOG("==> eps      = $eps");
  161. LOG("==> ifiles   = $ifiles");
  162.  
  163. # General options
  164. if ($ppm) {
  165.     LOG("Generate .ppm files ...");
  166.     $ppm = 1;
  167. }
  168. if ($norun) {
  169.     LOG("no compile file-pdf.tex");
  170.     $norun = 1;
  171. }
  172. if ($miktex) {
  173.     LOG("enable write 18 ...");
  174.     $miktex = 1;
  175. }
  176. if ($eps) {
  177.     LOG("Generate .eps files ...");
  178.     $eps = 1;
  179. }
  180. if ($ifiles) {
  181.     LOG("Generate .tex images files ...");
  182.     $ifiles = 1;
  183. }
  184. if ($all) {
  185.     LOG("Generate all images files ...");
  186.     $ifiles = $eps = $ppm = $clear = 1;
  187. }
  188. if ($nopdftk) {
  189.     LOG("Forced generate all images files ...");
  190.     $force = $ifiles = $eps = $ppm = $clear = 1;
  191. }
  192.  
  193. # Internal counter
  194. my $imgNo = 1;
  195.  
  196. # force mode , compile separte files
  197. if ($force) {
  198.     LOG("Running on [$path][$name][$ext]");
  199.     open my $FILE, '<', "$TeXfile";
  200.     LOG("force generate images...");
  201.     if   ( -d $imageDir ) { LOG("$imageDir exists") }
  202.     else                  { mkdir $imageDir, 0744; }
  203.     savePreamble($name);
  204.     runFile($name);
  205.     close $FILE;
  206.     close LOGfile;
  207. }
  208. else {
  209.     LOG("Running on [$path][$name][$ext]");
  210.     open my $FILE, '<', "$TeXfile";
  211.     if ( !$noImages ) {
  212.         if ( -d $imageDir ) { LOG("$imageDir exists") }
  213.         else {
  214.             mkdir $imageDir, 0744;
  215.             LOG("Imagedir created");
  216.         }
  217.         LOG("go to savePreamble ... ");
  218.         runBurst($tempDir);
  219.         savePreamble($name);
  220.         runFile($name);
  221.         LOG("done!\n go to runFile ...");
  222.         LOG("done!");
  223.         close LOGfile;
  224.     }
  225.                 close $FILE;
  226. }
  227.  
  228. #------------ Create filename-pics.pdf, split and generate .ppm
  229. sub runBurst {
  230.     if ($force) { print "Force mode"; }
  231.     else {
  232.         # Append preview
  233.         my $entrada = "$TeXfile";
  234.         my $salida  = "$name-pics.tex";
  235.         open my $ENTRADA,'<', "$entrada";
  236.         open my $SALIDA,'>',"$salida";
  237.         print $SALIDA "\\AtBeginDocument\{\n";
  238.         print $SALIDA "\\RequirePackage\[active,tightpage\]\{preview\}\n";
  239.         print $SALIDA "\\renewcommand\\PreviewBbAdjust\{-600pt -600pt 600pt 600pt\}\n";
  240.         print $SALIDA "\\PreviewEnvironment\{tikzpicture\}\}\n";
  241.  
  242.         while ( my $linea = <$ENTRADA> ) {
  243.             print $SALIDA $linea;
  244.         }
  245.         close $ENTRADA;
  246.         close $SALIDA;
  247.  
  248.         # close preview
  249.  
  250.         if ($miktex) { system("pdflatex -enable-write18 -interaction=batchmode $name"); }
  251.         else {
  252.             system("pdflatex -shell-escape -interaction=batchmode $tempDir/$name-pics.tex");
  253.             system("pdfcrop $tempDir/$name-pics.pdf $tempDir/$name-pics.pdf");
  254.             system("pdftk $name-pics.pdf burst output $imageDir/$name-tikz-\%1d.pdf");
  255.         }
  256.         if ($ppm) {
  257.             system("pdftoppm -r  $DPI $name-pics.pdf $imageDir/$name-tikz");
  258.         }
  259.     }
  260. }
  261.  
  262. #------------ end pdftk burst
  263. LOG("runpdfTeX ... ");
  264. runpdfTeX( "$path$name", $name );
  265. LOG("all finished ... :-)");
  266.  
  267. # Save preable
  268. sub savePreamble {
  269.     my $filename = pop;
  270.     LOG("----- Start Preamble -----");
  271.     open my $FILEp, '>', "$tempDir/$filename.preamble";
  272.     open my $FILE,  '<', "$name.tex";
  273.     while (<$FILE>) {
  274.         my $i = index( $_, "begin{document}" );
  275.         if ( $i > 0 ) {
  276.             if ( $i > 1 ) { print $FILEp substr( $_, 0, --$i ); }
  277.             if ($force) {
  278.                 print $FILEp "\\pagestyle{empty}\n";
  279.             }
  280.             close $FILEp;
  281.             LOG("----- Close Preamble ------");
  282.             return;
  283.         }
  284.         else {
  285.             print $FILEp "$_";
  286.             LOG("$_");
  287.         }
  288.     }
  289.  
  290.     close $FILE;
  291.     close $FILEp;
  292.     if ($verbose) { LOG("<-----Preamble<----"); }
  293.     return;
  294. }
  295.  
  296. sub searchTiKZ {
  297.     my @TikZ        = ();
  298.     my @TIKZtotal   = ();
  299.     my $depth       = -1;
  300.     my $type        = -1;
  301.     my $EndDocument = 0;
  302.     my $iVerb       = 0;
  303.     open my $FILE, '<', "$name.tex";
  304.     while (<$FILE>) {
  305.  
  306.         if ( !$EndDocument ) {
  307.             chomp;
  308.             my $line = $_;
  309.             if ( !$iVerb ) {
  310.                 $iVerb = ( ( index( $line, "begin{verbatim}" ) > 0 ) or ( index( $line, "begin{lstlisting}" ) > 0 ) );
  311.             }
  312.             if ( !$iVerb ) {
  313.                 my $iTIKZ = index( $line, "begin{tikzpicture}" );
  314.                 if ( $type < 0 ) {
  315.                     if ( $iTIKZ > 0 ) {
  316.                         $type = 2;
  317.                         $line = substr( $line, $iTIKZ - 1 );
  318.                         LOG("TiKZ-line: $line");
  319.                     }
  320.                 }
  321.  
  322.                 if ( $type > 0 ) {
  323.                     LOG("searchTiKZ: set \$type=$type");
  324.                     $iTIKZ = index( $line, "end{tikzpicture}" );
  325.                     if ( $iTIKZ > 0 ) {
  326.                         LOG("searchTiKZ: $line");
  327.                         $type = -1;
  328.                         push @TikZ, substr( $line, 0, $iTIKZ + 16 );
  329.                         LOG("searchTiKZ: set \$type=$type");
  330.                         push @TIKZtotal, [@TikZ];
  331.                         LOG("---->TiKZ---->\n@TikZ\n<----TikZ<----");
  332.                         @TikZ = ();
  333.                     }
  334.                     else { push @TikZ, $line; }    # add line
  335.                 }
  336.                 my $i = index( $line, "end{document}" );
  337.                 if ( $i > 0 ) { $EndDocument++; LOG("EndDocument in searchTiKZ"); }
  338.             }
  339.             if ( ( index( $line, "end{verbatim}" ) > 0 ) or ( index( $line, "end{lstlisting}" ) > 0 ) ) { $iVerb = 0; }
  340.         }
  341.     }
  342.     if ($verbose) {
  343.         LOG("---->TIKZtotal---->");
  344.         for my $aref (@TIKZtotal) {
  345.             my @a = @$aref;
  346.             my $i = 1;
  347.             foreach (@a) { LOG( $a[$i] ); $i = $i + 1; }
  348.         }
  349.         LOG("<----TIKZtotal<----");
  350.     }
  351.     close $FILE;
  352.     return @TIKZtotal;
  353. }
  354.  
  355. # Creating ifile.tex and eps, pdf and ppm for images
  356. if ($force) {
  357.      sub runFORCE {
  358.         my $filename = pop;
  359.         if   ($miktex) { system("pdflatex -enable-write18 -interaction=batchmode $tempDir/$filename-tikz"); }
  360.         else           { system("pdflatex -shell-escape -interaction=batchmode $tempDir/$filename-tikz"); }
  361.         if ($ifiles) {
  362.             copy( "$filename-tikz.tex", "$imageDir/$filename-tikz-$imgNo.tex" );
  363.         }
  364.         system("pdfcrop $tempDir/$filename-tikz.pdf $imageDir/$filename-tikz-$imgNo.pdf");
  365.         if ($eps) {
  366.             system("pdftops -level3 -eps $imageDir/$filename-tikz-$imgNo.pdf $imageDir/$filename-tikz-$imgNo.eps");
  367.         }
  368.         if ($ppm) { system("pdftoppm -r $DPI $imageDir/$filename-tikz-$imgNo.pdf $imageDir/$filename-tikz-$imgNo"); }
  369.         $imgNo = $imgNo + 1;
  370.     }
  371. }
  372. else {
  373.  
  374.     # Creating ifiles.tex and .eps for images
  375.     sub runTeX {
  376.         my $filename = pop;
  377.         if ($eps) {
  378.             system("pdftops -level3 -eps $imageDir/$filename-$imgNo.pdf $imageDir/$filename-$imgNo.eps");
  379.         }
  380.         if ($ifiles) {
  381.             copy( "$filename.tex", "$imageDir/$filename-$imgNo.tex" );
  382.         }
  383.         $imgNo = $imgNo + 1;
  384.     }
  385. }
  386.  
  387. sub runFile {
  388.     my $filename  = pop;
  389.     my @TIKZarray = searchTiKZ();
  390.     if ($verbose) {
  391.         LOG("---->TIKZarray---->");
  392.         for my $aref (@TIKZarray) {
  393.             my @a = @$aref;
  394.             my $i = 1;
  395.             foreach (@a) { print LOG $a[$i] . "\n"; $i = $i + 1; }
  396.         }
  397.         LOG("<----TIKZarray<----");
  398.         my $no = @TIKZarray;
  399.         LOG( "TiKZ: " . $no . " TiKZ sequence(s)" );
  400.     }
  401.     for my $aref (@TIKZarray) {
  402.         my @TikZ = @$aref;
  403.         open my $FILEp,   '<', "$tempDir/$filename.preamble";
  404.         open my $FILEsub, '>', "$tempDir/$filename-tikz.tex";
  405.         while (<$FILEp>) { print $FILEsub $_; }
  406.         print $FILEsub "\\begin{document}\n";
  407.         if ($verbose) { LOG("\@TikZ: $_"); }
  408.         foreach (@TikZ) { print $FILEsub "$_\n"; }
  409.         print $FILEsub "\\end{document}";
  410.         close $FILEsub;
  411.         close $FILEp;
  412.  
  413.         if ($force) {
  414.             runFORCE("$name");
  415.         }
  416.         else {
  417.             runTeX("$tempDir/$name-tikz");
  418.         }
  419.     }
  420. }
  421.  
  422. # Renaming ppm need for correct name
  423. my $dren    = "$tempDir/$imageDir";
  424. my $fichero = '';
  425. my $ppmren  = '';
  426. my $renNo   = 1;
  427. if ( opendir( DIR, $dren ) ) {
  428.     foreach ( readdir DIR ) {
  429.         $fichero = $_;
  430.         if ( $fichero =~ /($name-tikz-)(\d+|\d+[-]\d+).ppm/ ) {
  431.             my $renNo   = int($2);
  432.             my $newname = "$1$renNo.ppm";
  433.             $ppmren = rename( "$dren/$fichero", "$dren/$newname" );
  434.         }
  435.     }
  436. }
  437. closedir DIR;
  438.  
  439. # Replace files
  440. sub runpdfTeX() {
  441.     my ( $name, $pdfname ) = @_;
  442.     open my $PDF,  '>', "$tempDir/$pdfname-pdf.tex";
  443.     open my $FILE, '<', "$name.tex";
  444.     print $PDF "\\RequirePackage{grfext}\n";
  445.     print $PDF "\\PrependGraphicsExtensions*{$Iext}\n";
  446.     print $PDF "\\RequirePackage{graphicx}\n";
  447.     print $PDF "\\graphicspath{{$imageDir/}}\n";
  448.     my $ignore      = 0;
  449.     my $IMGno       = 1;
  450.     my $depth       = -1;
  451.     my $type        = -1;
  452.     my $EndDocument = 0;
  453.     my $iVerb       = 0;
  454.  
  455.     while (<$FILE>) {
  456.         if ( !$iVerb ) {
  457.             $iVerb = ( ( index( $_, "begin{verbatim}" ) > 0 ) or ( index( $_, "begin{lstlisting}" ) > 0 ) );
  458.         }
  459.         if ( !$iVerb ) {
  460.             my $i = index( $_, "end{document}" );
  461.             if ( $i > 0 ) { print $PDF $_; $EndDocument++; LOG("EndDocument in runpdfTeX"); }
  462.             if ( !$EndDocument ) {
  463.                 my $iTIKZ = index( $_, "begin{tikzpicture}" );
  464.                 if ( $iTIKZ > 0 ) {
  465.                     $type   = 2;
  466.                     $ignore = 1;
  467.                     if ( $iTIKZ > 1 ) { print $PDF substr( $_, 0, --$iTIKZ ); }
  468.                     print $PDF "\\includegraphics[scale=$Iscale]{$pdfname-tikz-$IMGno}";
  469.                     $IMGno = $IMGno + 1;
  470.                 }
  471.                 if ( !$ignore ) { print $PDF "$_"; }
  472.                 if ( $type == 2 ) {
  473.                     my $iTIKZ = index( $_, "end{tikzpicture}" );
  474.                     if ( $iTIKZ > 0 ) {
  475.                         print $PDF substr( $_, $iTIKZ + 16 );
  476.                         $ignore = 0;
  477.                         $type   = -1;
  478.                     }
  479.                 }
  480.             }
  481.         }
  482.         else { print $PDF $_; }
  483.         if ( ( index( $_, "end{verbatim}" ) > 0 ) or ( index( $_, "end{lstlisting}" ) > 0 ) ) { $iVerb = 0; }
  484.     }
  485.     close $FILE;
  486.     close $PDF;
  487.  
  488.     if ($norun) { print "Done\n"; }
  489.     else {
  490.         system("pdflatex -interaction=batchmode $pdfname-pdf");
  491.         if ($ppm) {
  492.             print "If you need to create JPG/PNG type cd $imageDir and run\n";
  493.             print "mogrify -format jpg *.ppm\n";
  494.         }
  495.         print "Done\n";
  496.     }
  497.     if ($clear) {
  498.         if ($force) {
  499.             unlink "$tempDir/$name-tikz.pdf";
  500.             unlink "$tempDir/$name-tikz.aux";
  501.             unlink "$tempDir/$name-tikz.log";
  502.             unlink "$tempDir/$name-tikz.tex";
  503.                                                 unlink "$tempDir/$name.plog";
  504.                                                 unlink "$tempDir/$name.preamble";
  505.                                                 unlink "$tempDir/$name-pdf.aux";
  506.                                                 unlink "$tempDir/$name-pdf.log";
  507.                                                
  508.         }
  509.         else {
  510.                                                 unlink "$tempDir/$name.plog";
  511.                                                 unlink "$tempDir/$name.preamble";
  512.                                                 unlink "$tempDir/$name-pdf.aux";
  513.                                                 unlink "$tempDir/$name-pdf.log";
  514.             unlink "$tempDir/doc_data.txt";
  515.             unlink "$tempDir/$name-pics.pdf";
  516.             unlink "$tempDir/$name-pics.tex";
  517.             unlink "$tempDir/$name-pics.aux";
  518.             unlink "$tempDir/$name-pics.log";
  519.                                                 unlink "$tempDir/$name-tikz.tex";
  520.  
  521.         }
  522.     }
  523. }
  524.  
  525. sub LOG() {
  526.     if ($verbose) { print LOGfile "@_\n"; }
  527. }
  528. __END__
Coloreado en 0.014 segundos, usando GeSHi 1.0.8.4
Última edición por pablgonz el 2012-01-18 15:34 @690, editado 2 veces en total
pablgonz
Perlero nuevo
Perlero nuevo
 
Mensajes: 236
Registrado: 2010-09-08 21:03 @919
Ubicación: Concepción (Chile)

Re: Consulta sobre || y or

Notapor explorer » 2012-01-18 06:57 @331

Formateando el código con Perltidy, queda claro que el close() de la línea 223 debería estar después de la 225.
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Consulta sobre || y or

Notapor pablgonz » 2012-01-18 15:37 @692

Cambie la linea que me indicaste y edite el código que estaba más arriba (ahora usando Perltidy :D ), agregue los unlink que necesitaba y modifique un par de cosas que me faltaban, ¿alguna sugerencia respecto al código? (errores, etc.)
pablgonz
Perlero nuevo
Perlero nuevo
 
Mensajes: 236
Registrado: 2010-09-08 21:03 @919
Ubicación: Concepción (Chile)

Re: Consulta sobre || y or

Notapor pablgonz » 2012-01-19 08:31 @397

Ya, creo que esto sería la versión final del script. Vine por una consulta y la aclaré con creces.

Solucioné los errores que me daba autodie, y reparé una opción que no funcionaba como quería.

Agradecido por todo.
Pablo.
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $argv:q'
  2.     if 0;
  3.  
  4. use strict;                            # to be sure, that all is safe ... :-)
  5.  
  6. # $Id: tikz2pdf.pl 2012-01-17 08:41:35Z Pablo $
  7. # v. 0.1   Extract tikzpicture, based on pst2pdf by Herbert Voss
  8. # 2012-01-17      (c) Pablo González Luengo
  9. # Thanks to Giuseppe Matarazzo
  10. # Couple to have the complete operation of the script, you need some software (Linux and Windows)
  11. # xpdf (needed to create EPS / PPM)
  12. # gnuplot (not necessary if not called from TiKZ)
  13. # pdftk (not necessary with the-pdftk)
  14. # ImageMagick (required if you want to create JPG / PNG or other format)
  15. #
  16. use File::Path;
  17. use File::Copy;
  18. use File::Basename;
  19. use IO::File;
  20. use Getopt::Long;
  21. use autodie;
  22.  
  23. #----------------------- User part begin ------------------------
  24. my $imageDir = "images";
  25. my $Iext     = ".pdf";                 # leave empty, if not a special one
  26. my $tempDir  = ".";                    # temporary directory
  27. my $verbose  = 1;                      # 0 or 1, logfile
  28. my $clear    = 0;                      # 0 or 1, clears all temporary files
  29. my $DPI      = 75;                     # very low value for the png's
  30. my $Iscale   = 1;                      # for \includegraphics
  31. my $noImages = 0;                      # 1->create no images
  32. my $force    = 0;                      # 1->force create images
  33. my $ppm      = 0;                      # 1->create .ppm files
  34. my $norun    = 0;                      # 1->runs pdflatex
  35. my $miktex   = 0;                      # 1->runs pdlatex for miktex
  36. my $eps      = 0;                      # 1->create .eps files
  37. my $ifiles   = 0;                      # 1->create image files .tex
  38. my $all      = 0;                      # 1->create all images and files for type
  39. my $nopdftk  = 0;                      # 1->create all images and files for type in force mode
  40.  
  41. #----------------------- User part end ---------------------------
  42. #----------------------- program identification, options and help
  43. my $program   = "tikz2pdf";
  44. my $ident     = '$Id: tikz2pdf.pl 2012-01-17 pablo $';
  45. my $copyright = <<END_COPYRIGHT ;
  46. Copyright 2012-01-17 (c) Pablo Gonzalez L <pablgonz\@yahoo.com>
  47. END_COPYRIGHT
  48. my $licensetxt = <<END_LICENSE ;
  49.     This program is free software; you can redistribute it and/or modify
  50.     it under the terms of the GNU General Public License as published by
  51.     the Free Software Foundation; either version 2 of the License, or
  52.     (at your option) any later version.
  53.  
  54.     This program is distributed in the hope that it will be useful, but
  55.     WITHOUT ANY WARRANTY; without even the implied warranty of
  56.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  57.     General Public License for more details.
  58.  
  59.     You should have received a copy of the GNU General Public License
  60.     along with this program; if not, write to the Free Software
  61.     Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  62.     MA  02111-1307  USA
  63. END_LICENSE
  64. my $title = "$program $ident\n";
  65. my $usage = <<"END_OF_USAGE";
  66. ${title}Usage: $program <texfile.tex>  [Options]
  67. tikz2pdf run a TeX source, and extract all TiKZ-related part as
  68.         single images  (pdf or eps or ppm, default pdf)
  69.         and then runs pdflatex. See tikz2pdf documentation for more info
  70. Options:
  71.   --help          - display this help and exit
  72.   --version       - display version information and exit
  73.   --license       - display license information and exit
  74.   --imageDir      - the dir for the created images (default images)
  75.   --DPI=<int>     - the dots per inch for a cretaed ppm files (default 75)
  76.   --ppm           - create .ppm files
  77.   --eps           - create .eps files  
  78.   --Iscale=<real> - the value for [scale=] in \\includegraphics
  79.   --noImages      - generate files without compile (need -norun)
  80.   --verbose       - creates long log
  81.   --clear         - delete all temp files
  82.   --norun         - create file-pdf.tex, but, no run pdflatex
  83.   --miktex        - for miktex users -enable-write18
  84.   --ifiles        - create images files (.tex) for all TiKZ enviroment
  85.   --force         - create images whitout pdftk.
  86.   --all           - create all image type and images.tex      
  87.   --nopdftk       - create all image type and images.tex in force mode
  88. Examples:
  89. * $program test.tex --all
  90. * produce test-pdf.tex and ppm,eps,tex and pdf for TiKZ-enviroment in image dir
  91. END_OF_USAGE
  92.  
  93. #
  94. my $result = GetOptions(
  95.     "help",
  96.     "version",
  97.     "license",
  98.     "DPI=i"      => \$DPI,             # numeric
  99.     "Iscale=f"   => \$Iscale,          # real
  100.     "imageDir=s" => \$imageDir,        # string
  101.     "tempDir=s"  => \$tempDir,         # string
  102.     "Iext=s"     => \$Iext,            # string
  103.     "clear"      => \$clear,           # flag
  104.     "noImages"   => \$noImages,        # flag
  105.     "force"      => \$force,           # flag
  106.     "ppm"        => \$ppm,             # flag
  107.     "norun"      => \$norun,           # flag
  108.     "miktex"     => \$miktex,          # flag
  109.     "eps"        => \$eps,             # flag
  110.     "ifiles"     => \$ifiles,          # flag
  111.     "all"        => \$all,             # flag
  112.     "nopdftk"    => \$nopdftk,         # flag
  113.     "verbose"    => \$verbose,
  114. ) or die $usage;
  115.  
  116. # help functions
  117. sub errorUsage { die "Error: @_ (try --help for more information)\n"; }
  118.  
  119. # options for command line
  120. if ($::opt_help) {
  121.     print $usage;
  122.     exit(0);
  123. }
  124. if ($::opt_version) {
  125.     print $title;
  126.     print $copyright;
  127.     exit(0);
  128. }
  129. if ($::opt_license) {
  130.     print $licensetxt;
  131.     exit(0);
  132. }
  133.  
  134. # open file
  135. my $InputFilename = "";
  136. @ARGV > 0 or errorUsage "Input filename missing";
  137. @ARGV < 2 or errorUsage "Unknown option or too many input files";
  138. $InputFilename = $ARGV[0];
  139.  
  140. # end open file
  141. my @SuffixList = ( ".tex", "", ".ltx" );    # possible extensions
  142. my ( $name, $path, $ext ) = fileparse( $ARGV[0], @SuffixList );
  143. if ( $ext eq "" ) { $ext = ".tex"; }   # me need the extension as well
  144. my $TeXfile = "$path$name$ext";
  145. my $Logfile = "$tempDir/$name.plog";   # our own log file
  146. open( LOGfile, ">$Logfile" );
  147. LOG("Parameters:");
  148. LOG("==> imageDir = $imageDir");
  149. LOG("==> Iext     = $Iext");
  150. LOG("==> DPI      = $DPI");
  151. LOG("==> Iscale   = $Iscale");
  152. LOG("==> tempDir  = $tempDir");
  153. LOG("==> verbose  = $verbose");
  154. LOG("==> clear    = $clear");
  155. LOG("==> noImages = $noImages");
  156. LOG("==> force    = $force");
  157. LOG("==> ppm      = $ppm");
  158. LOG("==> norun    = $norun");
  159. LOG("==> miktex   = $miktex");
  160. LOG("==> eps      = $eps");
  161. LOG("==> ifiles   = $ifiles");
  162.  
  163. # General options
  164. if ($ppm) {
  165.     LOG("Generate .ppm files ...");
  166.     $ppm = 1;
  167. }
  168. if ($norun) {
  169.     LOG("no compile file-pdf.tex");
  170.     $norun = 1;
  171. }
  172. if ($miktex) {
  173.     LOG("enable write 18 ...");
  174.     $miktex = 1;
  175. }
  176. if ($eps) {
  177.     LOG("Generate .eps files ...");
  178.     $eps = 1;
  179. }
  180. if ($ifiles) {
  181.     LOG("Generate .tex images files ...");
  182.     $ifiles = 1;
  183. }
  184. if ($all) {
  185.     LOG("Generate all images files ...");
  186.     $ifiles = $eps = $ppm = $clear = 1;
  187. }
  188. if ($nopdftk) {
  189.     LOG("Forced generate all images files ...");
  190.     $force = $ifiles = $eps = $ppm = $clear = 1;
  191. }
  192.  
  193. # Internal counter
  194. my $imgNo = 1;
  195.  
  196. # force mode , compile separte files
  197. if ($force) {
  198.     LOG("Running on [$path][$name][$ext]");
  199.     open my $FILE, '<', "$TeXfile";
  200.     LOG("force generate images...");
  201.     if   ( -d $imageDir ) { LOG("$imageDir exists") }
  202.     else                  { mkdir $imageDir, 0744; }
  203.     savePreamble($name);
  204.     runFile($name);
  205.     close $FILE;
  206.     close LOGfile;
  207. }
  208. else {
  209.     LOG("Running on [$path][$name][$ext]");
  210.     open my $FILE, '<', "$TeXfile";
  211.     if ( !$noImages ) {
  212.         if ( -d $imageDir ) { LOG("$imageDir exists") }
  213.         else {
  214.             mkdir $imageDir, 0744;
  215.             LOG("Imagedir created");
  216.         }
  217.         LOG("go to savePreamble ... ");
  218.         runBurst($tempDir);
  219.         savePreamble($name);
  220.         runFile($name);
  221.         LOG("done!\n go to runFile ...");
  222.         LOG("done!");
  223.         close LOGfile;
  224.     }
  225.     close $FILE;
  226. }
  227.  
  228. #------------ Create filename-pics.pdf, split and generate .ppm
  229. sub runBurst {
  230.     if ($force) { print "Force mode"; }
  231.     else {
  232.  
  233.         # Append preview
  234.         my $entrada = "$TeXfile";
  235.         my $salida  = "$name-pics.tex";
  236.         open my $ENTRADA, '<', "$entrada";
  237.         open my $SALIDA,  '>', "$salida";
  238.         print $SALIDA "\\AtBeginDocument\{\n";
  239.         print $SALIDA "\\RequirePackage\[active,tightpage\]\{preview\}\n";
  240.         print $SALIDA "\\renewcommand\\PreviewBbAdjust\{-600pt -600pt 600pt 600pt\}\n";
  241.         print $SALIDA "\\PreviewEnvironment\{tikzpicture\}\}\n";
  242.  
  243.         while ( my $linea = <$ENTRADA> ) {
  244.             print $SALIDA $linea;
  245.         }
  246.         close $ENTRADA;
  247.         close $SALIDA;
  248.  
  249.         # close preview
  250.  
  251.         if   ($miktex) { system("pdflatex -enable-write18 -interaction=batchmode $tempDir/$name-pics.tex"); }
  252.         else           { system("pdflatex -shell-escape -interaction=batchmode $tempDir/$name-pics.tex"); }
  253.         system("pdfcrop $tempDir/$name-pics.pdf $tempDir/$name-pics.pdf");
  254.         system("pdftk $name-pics.pdf burst output $imageDir/$name-tikz-\%1d.pdf");
  255.  
  256.         if ($ppm) {
  257.             system("pdftoppm -r  $DPI $name-pics.pdf $imageDir/$name-tikz");
  258.         }
  259.     }
  260. }
  261.  
  262. #------------ end pdftk burst
  263. LOG("runpdfTeX ... ");
  264. runpdfTeX( "$path$name", $name );
  265. LOG("all finished ... :-)");
  266.  
  267. # Save preable
  268. sub savePreamble {
  269.     my $filename = pop;
  270.     LOG("----- Start Preamble -----");
  271.     open my $FILEp, '>', "$tempDir/$filename.preamble";
  272.     open my $FILE,  '<', "$name.tex";
  273.     while (<$FILE>) {
  274.         my $i = index( $_, "begin{document}" );
  275.         if ( $i > 0 ) {
  276.             if ( $i > 1 ) { print $FILEp substr( $_, 0, --$i ); }
  277.             if ($force) {
  278.                 print $FILEp "\\pagestyle{empty}\n";
  279.             }
  280.             close $FILEp;
  281.             LOG("----- Close Preamble ------");
  282.             return;
  283.         }
  284.         else {
  285.             print $FILEp "$_";
  286.             LOG("$_");
  287.         }
  288.     }
  289.  
  290.     close $FILE;
  291.     close $FILEp;
  292.     if ($verbose) { LOG("<-----Preamble<----"); }
  293.     return;
  294. }
  295.  
  296. sub searchTiKZ {
  297.     my @TikZ        = ();
  298.     my @TIKZtotal   = ();
  299.     my $depth       = -1;
  300.     my $type        = -1;
  301.     my $EndDocument = 0;
  302.     my $iVerb       = 0;
  303.     open my $FILE, '<', "$name.tex";
  304.     while (<$FILE>) {
  305.  
  306.         if ( !$EndDocument ) {
  307.             chomp;
  308.             my $line = $_;
  309.             if ( !$iVerb ) {
  310.                 $iVerb = ( ( index( $line, "begin{verbatim}" ) > 0 ) or ( index( $line, "begin{lstlisting}" ) > 0 ) );
  311.             }
  312.             if ( !$iVerb ) {
  313.                 my $iTIKZ = index( $line, "begin{tikzpicture}" );
  314.                 if ( $type < 0 ) {
  315.                     if ( $iTIKZ > 0 ) {
  316.                         $type = 2;
  317.                         $line = substr( $line, $iTIKZ - 1 );
  318.                         LOG("TiKZ-line: $line");
  319.                     }
  320.                 }
  321.  
  322.                 if ( $type > 0 ) {
  323.                     LOG("searchTiKZ: set \$type=$type");
  324.                     $iTIKZ = index( $line, "end{tikzpicture}" );
  325.                     if ( $iTIKZ > 0 ) {
  326.                         LOG("searchTiKZ: $line");
  327.                         $type = -1;
  328.                         push @TikZ, substr( $line, 0, $iTIKZ + 16 );
  329.                         LOG("searchTiKZ: set \$type=$type");
  330.                         push @TIKZtotal, [@TikZ];
  331.                         LOG("---->TiKZ---->\n@TikZ\n<----TikZ<----");
  332.                         @TikZ = ();
  333.                     }
  334.                     else { push @TikZ, $line; }    # add line
  335.                 }
  336.                 my $i = index( $line, "end{document}" );
  337.                 if ( $i > 0 ) { $EndDocument++; LOG("EndDocument in searchTiKZ"); }
  338.             }
  339.             if ( ( index( $line, "end{verbatim}" ) > 0 ) or ( index( $line, "end{lstlisting}" ) > 0 ) ) { $iVerb = 0; }
  340.         }
  341.     }
  342.     if ($verbose) {
  343.         LOG("---->TIKZtotal---->");
  344.         for my $aref (@TIKZtotal) {
  345.             my @a = @$aref;
  346.             my $i = 1;
  347.             foreach (@a) { LOG( $a[$i] ); $i = $i + 1; }
  348.         }
  349.         LOG("<----TIKZtotal<----");
  350.     }
  351.     close $FILE;
  352.     return @TIKZtotal;
  353. }
  354.  
  355. # Creating ifile.tex and eps, pdf and ppm for images
  356. if ($force) {
  357.  
  358.     sub runFORCE {
  359.         my $filename = pop;
  360.         if   ($miktex) { system("pdflatex -enable-write18 -interaction=batchmode $tempDir/$filename-tikz"); }
  361.         else           { system("pdflatex -shell-escape -interaction=batchmode $tempDir/$filename-tikz"); }
  362.         if ($ifiles) {
  363.             copy( "$filename-tikz.tex", "$imageDir/$filename-tikz-$imgNo.tex" );
  364.         }
  365.         system("pdfcrop $tempDir/$filename-tikz.pdf $imageDir/$filename-tikz-$imgNo.pdf");
  366.         if ($eps) {
  367.             system("pdftops -level3 -eps $imageDir/$filename-tikz-$imgNo.pdf $imageDir/$filename-tikz-$imgNo.eps");
  368.         }
  369.         if ($ppm) { system("pdftoppm -r $DPI $imageDir/$filename-tikz-$imgNo.pdf $imageDir/$filename-tikz-$imgNo"); }
  370.         $imgNo = $imgNo + 1;
  371.     }
  372. }
  373. else {
  374.  
  375.     # Creating ifiles.tex and .eps for images
  376.     sub runTeX {
  377.         my $filename = pop;
  378.         if ($eps) {
  379.             system("pdftops -level3 -eps $imageDir/$filename-$imgNo.pdf $imageDir/$filename-$imgNo.eps");
  380.         }
  381.         if ($ifiles) {
  382.             copy( "$filename.tex", "$imageDir/$filename-$imgNo.tex" );
  383.         }
  384.         $imgNo = $imgNo + 1;
  385.     }
  386. }
  387.  
  388. sub runFile {
  389.     my $filename  = pop;
  390.     my @TIKZarray = searchTiKZ();
  391.     if ($verbose) {
  392.         LOG("---->TIKZarray---->");
  393.         for my $aref (@TIKZarray) {
  394.             my @a = @$aref;
  395.             my $i = 1;
  396.             foreach (@a) { print LOG $a[$i] . "\n"; $i = $i + 1; }
  397.         }
  398.         LOG("<----TIKZarray<----");
  399.         my $no = @TIKZarray;
  400.         LOG( "TiKZ: " . $no . " TiKZ sequence(s)" );
  401.     }
  402.     for my $aref (@TIKZarray) {
  403.         my @TikZ = @$aref;
  404.         open my $FILEp,   '<', "$tempDir/$filename.preamble";
  405.         open my $FILEsub, '>', "$tempDir/$filename-tikz.tex";
  406.         while (<$FILEp>) { print $FILEsub $_; }
  407.         print $FILEsub "\\begin{document}\n";
  408.         if ($verbose) { LOG("\@TikZ: $_"); }
  409.         foreach (@TikZ) { print $FILEsub "$_\n"; }
  410.         print $FILEsub "\\end{document}";
  411.         close $FILEsub;
  412.         close $FILEp;
  413.  
  414.         if ($force) {
  415.             runFORCE("$name");
  416.         }
  417.         else {
  418.             runTeX("$tempDir/$name-tikz");
  419.         }
  420.     }
  421. }
  422.  
  423. # Renaming ppm need for correct name
  424. my $dren    = "$tempDir/$imageDir";
  425. my $fichero = '';
  426. my $ppmren  = '';
  427. my $renNo   = 1;
  428. if ( opendir( DIR, $dren ) ) {
  429.     foreach ( readdir DIR ) {
  430.         $fichero = $_;
  431.         if ( $fichero =~ /($name-tikz-)(\d+|\d+[-]\d+).ppm/ ) {
  432.             my $renNo   = int($2);
  433.             my $newname = "$1$renNo.ppm";
  434.             $ppmren = rename( "$dren/$fichero", "$dren/$newname" );
  435.         }
  436.     }
  437. }
  438. closedir DIR;
  439.  
  440. # Replace files
  441. sub runpdfTeX() {
  442.     my ( $name, $pdfname ) = @_;
  443.     open my $PDF,  '>', "$tempDir/$pdfname-pdf.tex";
  444.     open my $FILE, '<', "$name.tex";
  445.     print $PDF "\\RequirePackage{grfext}\n";
  446.     print $PDF "\\PrependGraphicsExtensions*{$Iext}\n";
  447.     print $PDF "\\RequirePackage{graphicx}\n";
  448.     print $PDF "\\graphicspath{{$imageDir/}}\n";
  449.     my $ignore      = 0;
  450.     my $IMGno       = 1;
  451.     my $depth       = -1;
  452.     my $type        = -1;
  453.     my $EndDocument = 0;
  454.     my $iVerb       = 0;
  455.  
  456.     while (<$FILE>) {
  457.         if ( !$iVerb ) {
  458.             $iVerb = ( ( index( $_, "begin{verbatim}" ) > 0 ) or ( index( $_, "begin{lstlisting}" ) > 0 ) );
  459.         }
  460.         if ( !$iVerb ) {
  461.             my $i = index( $_, "end{document}" );
  462.             if ( $i > 0 ) { print $PDF $_; $EndDocument++; LOG("EndDocument in runpdfTeX"); }
  463.             if ( !$EndDocument ) {
  464.                 my $iTIKZ = index( $_, "begin{tikzpicture}" );
  465.                 if ( $iTIKZ > 0 ) {
  466.                     $type   = 2;
  467.                     $ignore = 1;
  468.                     if ( $iTIKZ > 1 ) { print $PDF substr( $_, 0, --$iTIKZ ); }
  469.                     print $PDF "\\includegraphics[scale=$Iscale]{$pdfname-tikz-$IMGno}";
  470.                     $IMGno = $IMGno + 1;
  471.                 }
  472.                 if ( !$ignore ) { print $PDF "$_"; }
  473.                 if ( $type == 2 ) {
  474.                     my $iTIKZ = index( $_, "end{tikzpicture}" );
  475.                     if ( $iTIKZ > 0 ) {
  476.                         print $PDF substr( $_, $iTIKZ + 16 );
  477.                         $ignore = 0;
  478.                         $type   = -1;
  479.                     }
  480.                 }
  481.             }
  482.         }
  483.         else { print $PDF $_; }
  484.         if ( ( index( $_, "end{verbatim}" ) > 0 ) or ( index( $_, "end{lstlisting}" ) > 0 ) ) { $iVerb = 0; }
  485.     }
  486.     close $FILE;
  487.     close $PDF;
  488.  
  489.     if ($norun) { print "Done\n"; }
  490.     else {
  491.         system("pdflatex -interaction=batchmode $pdfname-pdf");
  492.         if ($ppm) {
  493.             print "If you need to create JPG/PNG type cd $imageDir and run\n";
  494.             print "mogrify -format jpg *.ppm\n";
  495.         }
  496.         print "Done\n";
  497.     }
  498.     if ($clear) {
  499.         if ($force) {
  500.             unlink "$tempDir/$name-tikz.pdf";
  501.             unlink "$tempDir/$name-tikz.aux";
  502.             unlink "$tempDir/$name-tikz.log";
  503.             unlink "$tempDir/$name-tikz.tex";
  504.             unlink "$tempDir/$name.plog";
  505.             unlink "$tempDir/$name.preamble";
  506.             unlink "$tempDir/$name-pdf.aux";
  507.             unlink "$tempDir/$name-pdf.log";
  508.  
  509.         }
  510.         else {
  511.             unlink "$tempDir/$name.plog";
  512.             unlink "$tempDir/$name.preamble";
  513.             unlink "$tempDir/$name-pdf.aux";
  514.             unlink "$tempDir/$name-pdf.log";
  515.             unlink "$tempDir/doc_data.txt";
  516.             unlink "$tempDir/$name-pics.pdf";
  517.             unlink "$tempDir/$name-pics.tex";
  518.             unlink "$tempDir/$name-pics.aux";
  519.             unlink "$tempDir/$name-pics.log";
  520.             unlink "$tempDir/$name-tikz.tex";
  521.  
  522.         }
  523.     }
  524. }
  525.  
  526. sub LOG() {
  527.     if ($verbose) { print LOGfile "@_\n"; }
  528. }
  529. __END__
  530.  
Coloreado en 0.013 segundos, usando GeSHi 1.0.8.4
Última edición por explorer el 2012-01-19 11:28 @519, editado 1 vez en total
Razón: Formateado de código con Perltidy
pablgonz
Perlero nuevo
Perlero nuevo
 
Mensajes: 236
Registrado: 2010-09-08 21:03 @919
Ubicación: Concepción (Chile)

Anterior

Volver a Básico

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 43 invitados

cron