I have script comments (adding % latex file) following some lines with %, the problem is that I want to comment on the lines just before the first \begin{document} and not found after this. I use split and tie:: file, but the script to comment all lines (\usepa...) in the file. I want is to read and edit before \ begin {document} and not after the specified line, then save the changes to that file, any help is appreciated... this is the code
#!/usr/bin/perl -w use strict; use Tie::File; #open my $archivo = 'test-pdf.tex'; my @coment=split(/\\begin{document}/, $archivo,2); #Usamos tie tie @coment, 'Tie::File', $archivo or die "No coment lines: $!"; #search foreach my $line (@coment) { # Coment $line =~ s/(\\usepackage){pst/\%\\usepackage{pst/i; } #close untie @coment;
example test-pdf.tex (before run script)
\RequirePackage{graphicx} \let\IncludeGraphics\includegraphics \graphicspath{{images/}} \documentclass[10pt]{article} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage{pstricks} \usepackage{pstricks-add} \usepackage[spanish]{babel} \usepackage{microtype}% sólo pdftex \begin{document} Example code \begin{verbatim} \documentclass[10pt]{article} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage{pstricks} \usepackage{pstricks-add} \usepackage[spanish]{babel} \usepackage{microtype}% sólo pdflatex \begin{document} \begin{pspicture}[showgrid=true](4,2) \psscaleboxto(8,2){Hola} \end{pspicture} \begin{pspicture}[showgrid=true](4,2) \psscaleboxto(4,2){foo bar} \end{pspicture} \end{document} \end{verbatim} Obtain \IncludeGraphics[scale=1]{test-tmp-0.pdf} and \IncludeGraphics[scale=1]{test-tmp-1.pdf} \end{document}
this is output test-pdf.tex (after run script)
\RequirePackage{graphicx} \let\IncludeGraphics\includegraphics \graphicspath{{images/}} \documentclass[10pt]{article} \usepackage[T1]{fontenc} \usepackage{lmodern} %\usepackage{pstricks} this is ok %\usepackage{pstricks-add} this is ok \usepackage[spanish]{babel} \usepackage{microtype}% sólo pdftex \begin{document} Example code \begin{verbatim} \documentclass[10pt]{article} \usepackage[T1]{fontenc} \usepackage{lmodern} %\usepackage{pstricks} %%%%this is wrong %\usepackage{pstricks-add} %%%%this is wrong \usepackage[spanish]{babel} \usepackage{microtype}% sólo pdflatex \begin{document} \begin{pspicture}[showgrid=true](4,2) \psscaleboxto(8,2){Hola} \end{pspicture} \begin{pspicture}[showgrid=true](4,2) \psscaleboxto(4,2){foo bar} \end{pspicture} \end{document} \end{verbatim} Obtain \IncludeGraphics[scale=1]{test-tmp-0.pdf} and \IncludeGraphics[scale=1]{test-tmp-1.pdf} \end{document}
Thank for comments, (i think the problem its in open or split file)...

In reply to split and tie::file by pablgonz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.