[SP-pm] [Fwd: duvidas]
Alexei Znamensky
russoz at gmail.com
Thu May 28 14:16:18 PDT 2009
2009/5/28 Andre Carneiro <andregarciacarneiro em gmail.com>
> [...]
>
> Só implemente essa linha acima, se o seu arquivo for realmente muito
> pequeno. Caso contrário você pode fazer:
>
> <code>
>
> #$fh é o filehandle que eu sugeri mais acima...
> my $line = '';
> my $lnumber = 0;#contador de linhas.
> while(<$fh>) {
> $line = $_; $_
> if($line =~ m{$keyword}){
> print "\nACHEI! - $lnumber";
> }
> $lnumber++;
> }
>
> </code>
>
> Esse while pode ficar mais legível assim:
>
> <code>
> .
> .
> .
> $lnumber = 0;
> while($line = readline($fh)){
> if($line =~ m{$keyword}){
> print "\nACHEI! - $lnumber";
> }
> $lnumber++;
> }
> .
> .
> .
> </code>
>
Ou menos legível assim ;-)
<code>
while(<$fh>) {
print "\nACHEI! - $." if /$keyword/;
}
</code>
--
Alexei Znamensky [russoz_gmail_com] [russoz.wordpress.com] [
www.flickr.com/photos/alexeiz]
"Though we live in trying times, we're the ones who have to try"
-------------- Pr�xima Parte ----------
Um anexo em HTML foi limpo...
URL: <http://mail.pm.org/pipermail/saopaulo-pm/attachments/20090528/84f1a281/attachment.html>
More information about the SaoPaulo-pm
mailing list