<span style="font-family: courier new,monospace;">Henrique, seja bem vindo ao grupo e, sabe lá por Deus, os ogros de plantão não fizeram alguns comentários sobre o teu código. Segue algumas alterações que podem transformar todos os teus códigos mais legíveis para você e todos demais.
<br><br>No inicio pode parecer chato, mas depois o negócio vai naturalmente.<br><br><span style="font-family: courier new,monospace;">&lt;code&gt;<br>#!/usr/bin/perl -w</span></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> use strict;<br>use Pod::Usage;<br>use Getopt::Long qw (:config pass_through );<br>use encoding &quot;latin1&quot;;
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"><br>my %config;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
my %dictionary = (</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;ç&#39; &nbsp; =&gt; &quot;\\c{c}&quot;,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;á&#39; &nbsp; =&gt; &quot;\\&#39;a&quot;,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;í&#39; &nbsp; =&gt; &quot;\\&#39;{\\i}&quot;,
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;é&#39; &nbsp; =&gt; &quot;\\&#39;e&quot;,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;ó&#39; &nbsp; =&gt; &quot;\\&#39;o&quot;,
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;ú&#39; &nbsp; =&gt; &quot;\\&#39;u&quot;,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;ã&#39; &nbsp; =&gt; &quot;\\~a&quot;,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;õ&#39; &nbsp; =&gt; &quot;\\~o&quot;,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;â&#39; &nbsp; =&gt; &quot;\\^a&quot;,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;ê&#39; &nbsp; =&gt; &quot;\\^e&quot;,
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;ô&#39; &nbsp; =&gt; &quot;\\^o&quot;,
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;ü&#39; &nbsp; =&gt; &#39;\\&quot;u&#39;);<br><br># Pega as opções de linha de comando e <br># armazena no hash config.
<br>GetOptions (<br>&nbsp; &#39;h|help!&#39;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&gt; \$config{help},<br>&nbsp; &#39;i|input=s&#39;&nbsp;&nbsp;&nbsp; =&gt; \$config{input},<br>&nbsp; &#39;o|output=s&#39;&nbsp;&nbsp; =&gt; \$config{output},<br>) or pod2usage(-verbose =&gt; 1) &amp;&amp; exit;
<br><br># Imprime o help nestas condições<br>if ( (&nbsp; defined $config{help} ) ||<br>&nbsp;&nbsp; &nbsp; (! defined $config{input}) ||<br>&nbsp; &nbsp;&nbsp; (! defined $config{output} ) ) {<br>&nbsp;&nbsp;&nbsp; pod2usage( -verbose =&gt; 1 );<br>&nbsp;&nbsp;&nbsp; exit 1;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">};<br><br>=item do_something<br><br>Esta função abre os arquivos de input e output e faz o trabalho de conversão.<br><br>=cut<br>do_something();<br><br>sub do_something {<br>
&nbsp; &nbsp; open INPUT,&#39;&lt;&#39;, $config{input} or <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; die &quot;Can&#39;t open file $config{input}. Error : $!&quot;;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
&nbsp;&nbsp;&nbsp; open OUTPUT,&#39;&gt;&#39;, $config{output} or <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; die &quot;Can&#39;t open file $config{output}. Error : $!&quot;;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; my $var;<br>&nbsp;&nbsp;&nbsp; my $length&nbsp;&nbsp;&nbsp;&nbsp; = 1024;<br>&nbsp;&nbsp;&nbsp; # Eu nao compreendi pq vc esta utilizando o read<br>&nbsp;&nbsp;&nbsp; # para ler este arquivo, ao invez de &lt;INPUT&gt;<br>&nbsp;&nbsp;&nbsp; my $bytes_read = read( INPUT, $var ,$length ); <br>
<br><br>&nbsp;&nbsp;&nbsp; while ( $bytes_read &gt; 0 ) {
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach my $key ( keys (%dictionary) ) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $var =~ s/$key/$dictionary{$key}/g;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print OUTPUT $var;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $bytes_read = read(INPUT, $var, $length);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"><br>&nbsp;&nbsp;&nbsp; close INPUT;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; close OUTPUT;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">=head1 NAME
</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">transformer.pl - Script transforma algo em alguma cosia.</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">=head1 SYNOPSIS</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
transformer.pl -help</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">transformer.pl -input meuarquivo.txt -o seuarquivo.tex</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">bcktimestamp [opções]</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">=head1 OPTIONS</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">=over 8
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">=item B&lt;-help&gt;
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Mostra uma mensagem de ajuda.
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
=item B&lt;-input&gt;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Informa o arquivo de entrada, o arquivo que será objeto do processamento.
</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">=item B&lt;-output&gt;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Informa o arquivo de saída do processamento</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
=back</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
=head1 DESCRIPTION</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
B&lt;Este programa&gt; vai ler o arquivo informado na opção B&lt;-input&gt;, fará algum processamento e gravará o resultado no arquivo informado na opção B&lt;-output&gt;.</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">=cut</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&lt;/code&gt;</span><br style="font-family: courier new,monospace;"></span>
<br>Teste este cara e nos fale o que vc acha ?<br><br>Abraços,<br><br>Solli M. Honório<br><br><div><span class="gmail_quote">On 7/11/07, <b class="gmail_sendername">Henrique Fleming</b> &lt;<a href="mailto:hfleming38@gmail.com">
hfleming38@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">O script abaixo pretende, em um texto escrito com encoding &quot;latin1&quot;, transformar caracteres
<br>acentuados em suas versões mais &quot;transportáveis&quot; em Latex. Basicamente ele deveria ler um<br>arquivo fornecido como argumento na linha de comando e gerar um arquivo &quot;
temp.tex&quot; em que<br>os caracteres acentuados foram substituídos pelas convenções Latex. Ele funciona perfeitamente<br>se a primeira coluna do hash %dictionary contiver apenas ascii. Da forma que está, há a reclamação
<br>de &quot;unrecognized character&quot; já para o c-cedilha. Tentei colocar &quot;use encoding &#39;latin1&#39; ; &quot; , mas não<br>funciona igualmente. <br><br>Alguém sabe como fazer isso?<br><br>Grato,<br><br>Henrique
<br><br>--------------------------------------------------------------------------------<br>#!/usr/bin/perl<br>#<br># Usar um Hash para dirigir um pattern replacement<br># Files are invoked at the command line<br>#<br># use encoding &quot;latin1&quot;;
<br>%dictionary = (<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ç&nbsp;&nbsp; =&gt; &quot;\\c{c}&quot;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; á&nbsp;&nbsp; =&gt; &quot;\\&#39;a&quot;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; í&nbsp;&nbsp; =&gt; &quot;\\&#39;{\\i}&quot;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; é&nbsp;&nbsp; =&gt; &quot;\\&#39;e&quot;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ó&nbsp;&nbsp; =&gt; &quot;\\&#39;o&quot;,
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ú&nbsp;&nbsp; =&gt; &quot;\\&#39;u&quot;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ã&nbsp;&nbsp; =&gt; &quot;\\~a&quot;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; õ&nbsp;&nbsp; =&gt; &quot;\\~o&quot;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; â&nbsp;&nbsp; =&gt; &quot;\\^a&quot;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ê&nbsp;&nbsp; =&gt; &quot;\\^e&quot;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ô&nbsp;&nbsp; =&gt; &quot;\\^o&quot;,
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ü&nbsp;&nbsp; =&gt; &#39;\\&quot;u&#39;,<br>);<br>$input = $ARGV[0];<br>open(INPUT,$input);<br>open(OUTPUT,&quot;&gt;temp.tex&quot;);<br>$length = 1024;<br>$bytes_read = read(INPUT, $var ,$length);<br>while ($bytes_read &gt; 0) {
<br>&nbsp;&nbsp; foreach $key (keys (%dictionary)) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $var =~ s/$key/$dictionary{$key}/g;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print OUTPUT $var;<br>&nbsp;&nbsp; $bytes_read= read(INPUT, $var, $length);<br>}<br>close(INPUT);<br>close(OUTPUT);<br>
<br>
---------------------------------------------------------------------------------------------------
<br>_______________________________________________<br>SaoPaulo-pm mailing list<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:SaoPaulo-pm@pm.org">SaoPaulo-pm@pm.org</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://mail.pm.org/mailman/listinfo/saopaulo-pm" target="_blank">
http://mail.pm.org/mailman/listinfo/saopaulo-pm</a><br></blockquote></div><br><br clear="all"><br>-- <br>&quot;o animal satisfeito dorme&quot;. - Guimarães Rosa