<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;"><code><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 "latin1";
</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;"> 'ç' => "\\c{c}",</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> 'á' => "\\'a",</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 'í' => "\\'{\\i}",
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 'é' => "\\'e",</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
'ó' => "\\'o",
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 'ú' => "\\'u",</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
'ã' => "\\~a",</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 'õ' => "\\~o",</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> 'â' => "\\^a",</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 'ê' => "\\^e",
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 'ô' => "\\^o",
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 'ü' => '\\"u');<br><br># Pega as opções de linha de comando e <br># armazena no hash config.
<br>GetOptions (<br> 'h|help!' => \$config{help},<br> 'i|input=s' => \$config{input},<br> 'o|output=s' => \$config{output},<br>) or pod2usage(-verbose => 1) && exit;
<br><br># Imprime o help nestas condições<br>if ( ( defined $config{help} ) ||<br> (! defined $config{input}) ||<br> (! defined $config{output} ) ) {<br> pod2usage( -verbose => 1 );<br> 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>
open INPUT,'<', $config{input} or <br> die "Can't open file $config{input}. Error : $!";</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
open OUTPUT,'>', $config{output} or <br> die "Can't open file $config{output}. Error : $!";</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
<br> my $var;<br> my $length = 1024;<br> # Eu nao compreendi pq vc esta utilizando o read<br> # para ler este arquivo, ao invez de <INPUT><br> my $bytes_read = read( INPUT, $var ,$length ); <br>
<br><br> while ( $bytes_read > 0 ) {
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> foreach my $key ( keys (%dictionary) ) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
$var =~ s/$key/$dictionary{$key}/g;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
<br> print OUTPUT $var;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> $bytes_read = read(INPUT, $var, $length);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"><br> close INPUT;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> 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;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">=item B<-help>
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </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;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
=item B<-input></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<-output></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;"> </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;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
B<Este programa> vai ler o arquivo informado na opção B<-input>, fará algum processamento e gravará o resultado no arquivo informado na opção B<-output>.</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </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;"></code></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> <<a href="mailto:hfleming38@gmail.com">
hfleming38@gmail.com</a>> 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 "latin1", transformar caracteres
<br>acentuados em suas versões mais "transportáveis" em Latex. Basicamente ele deveria ler um<br>arquivo fornecido como argumento na linha de comando e gerar um arquivo "
temp.tex" 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 "unrecognized character" já para o c-cedilha. Tentei colocar "use encoding 'latin1' ; " , 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 "latin1";
<br>%dictionary = (<br> ç => "\\c{c}",<br> á => "\\'a",<br> í => "\\'{\\i}",<br> é => "\\'e",<br> ó => "\\'o",
<br> ú => "\\'u",<br> ã => "\\~a",<br> õ => "\\~o",<br> â => "\\^a",<br> ê => "\\^e",<br> ô => "\\^o",
<br> ü => '\\"u',<br>);<br>$input = $ARGV[0];<br>open(INPUT,$input);<br>open(OUTPUT,">temp.tex");<br>$length = 1024;<br>$bytes_read = read(INPUT, $var ,$length);<br>while ($bytes_read > 0) {
<br> foreach $key (keys (%dictionary)) {<br> $var =~ s/$key/$dictionary{$key}/g;<br> }<br> print OUTPUT $var;<br> $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>"o animal satisfeito dorme". - Guimarães Rosa