[Cascavel-pm] Apagar nomes em arquivo.
Igor Lopes
igor.sutton em yahoo.co.uk
Quarta Setembro 5 04:58:30 PDT 2007
--- Rafael Lebrão Martins <rafamv1 em ig.com.br> wrote:
> copy( $file, $backup );
> open( ARQUIVO, '>', "$file" );
> open( BACKUP, '<', "$backup" );
>
> foreach my $name(@nomes) {
> excluir_nomes($name);
> }
>
> sub excluir_nomes{
> my $name = shift;
> foreach(<BACKUP>) {
> next if $_ =~ /^$name$/;
> print ARQUIVO $_;
> }}
> close (ARQUIVO);
> close (BACKUP);
# abre arquivos utilizando variaveis lexicas
open( my $in, '<', "in.txt" ) or die "Problemas ao
abrir in.txt: $!";
open( my $out, '>', "out.txt" ) or die "Problemas ao
abrir out.txt: $!";
# nomes que queremos excluir
my @names = qw(larry damian randal);
# cria expressao regular com os nomes declarados
my $names_re = sprintf "(?:%s)", join( '|', @names );
# itera arquivo de entrada
while (<$in>) {
chomp;
next if m{$names_re};
print $out $_, $/;
}
# fecha arquivos
close($out);
close($in);
___________________________________________________________
Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
now.
http://uk.answers.yahoo.com/
Mais detalhes sobre a lista de discussão Cascavel-pm