[Cascavel-pm] Manipulação de arquivo

Daniel Vinciguerra daniel_5h4d0w em hotmail.com
Terça Outubro 24 16:48:57 PDT 2006


Muito obrigado Thomas....
Com a ajuda de sua iplementação pude adaptar ao meu codigo em Perl Tk e 
fazer alguns ajustes ^^

Muito obrigado memso... segue ai o codigo completo....

#########################################################################

#!/opt/ActivePerl-5.8/bin/perl-static

#

use strict;
use Tk;
use Tk::Button;
use Tk::Entry;
use Tk::Frame;
use Tk::Label;
use Tk::Text;

my $mw=MainWindow->new(-title=>'Shadow Elf  [ Modo de Visualizaçao ]');
my $Frame_001 = $mw -> Frame ( -relief=>'flat' ) -> pack(-ipadx=>100, 
-ipady=>10, -fill=>'both');
my $Frame_002 = $mw -> Frame ( -relief=>'flat' ) -> pack(-ipadx=>100, 
-fill=>'both');
my $Frame_003 = $mw -> Frame ( -borderwidth=>1, -background=>'gray75', 
-label=>'Shadow Book [ Visualizaçao ]', -relief=>'raised' ) -> 
pack(-ipadx=>100, -ipady=>10, -fill=>'both');
my $Frame_004 = $mw -> Frame ( -relief=>'flat' ) -> pack(-ipadx=>100, 
-fill=>'both');
my $Bt_Fechar = $mw -> Button ( -relief=>'raised', -text=>'Fechar', 
-command=>sub{ exit; }, -state=>'normal' ) -> pack(-fill=>'both');
my $Tx_Consulta = $Frame_004 -> Scrolled ( 'Text', -height=>10, 
-borderwidth=>1, -relief=>'sunken', -scrollbars=>'e', -wrap=>'none', 
-width=>30, -state=>'normal' ) -> pack(-fill=>'both');
my $Lb_Consulta = $Frame_002 -> Label ( -justify=>'left', -text=>'Pesquisar 
por:', -relief=>'flat' ) -> pack(-anchor=>'w');
my $En_Consulta = $Frame_002 -> Entry ( -borderwidth=>1, 
-background=>'White', -justify=>'left', -relief=>'sunken', -width=>30, 
-state=>'normal' ) -> pack(-side=>'left', -anchor=>'nw');
my $Bt_Consulta = $Frame_002 -> Button ( -relief=>'raised', 
-text=>'Consultar', -command=>\&pesquisa, -state=>'normal' ) -> 
pack(-anchor=>'e');
MainLoop;

##### Functions Code....


sub pesquisa{

my ($data);
my (@dados);

## Checa se a variavel não esta setando um outro arquivo
if( $ENV{DATABASE}){
$data = $ENV{DATABASE}
}else{
$data = $ENV{HOME} . "/.DataBase";
}

## Recebe o NOME do Entry
my $nome = $En_Consulta->get;

## Abre o arquivo da agenda....
open (DB, "< $data");
while (<DB>) {
	chomp();
	if (/^$nome/i) {
		@dados = split (/:/, $_);
		last;
	}
}
if ($dados[0]) {

## Insere os dados no campo criado pelo widget Text caso algo seja 
encontrado
$Tx_Consulta -> insert('end',"
Nome:      $dados[0] \n
Endereço:  $dados[1] \n
Bairro:    $dados[2] \n
Cidade:    $dados[3] \n
Estado:    $dados[4] \n
Telefone:  $dados[5] \n
Celular:   $dados[6] \n
E-Mail:    $dados[7] \n");

} else {

## Senão retorna uma msg...
$Tx_Consulta -> insert('end',"Dados indisponíveis.\n");
}
close(DB);

}

#########################################################################




>From: Thomas Britis <thomas em tcnet.com.br>
>Reply-To: Cascavel Perl Mongers <cascavel-pm em pm.org>
>To: Cascavel Perl Mongers <cascavel-pm em pm.org>
>Subject: Re: [Cascavel-pm] Manipulação de arquivo
>Date: Mon, 23 Oct 2006 21:07:28 -0200
>
>my (@dados);
>my ($nome) = $ARGV[0]; # Recebe o nome como primeiro argumento
>open (F, "<Agenda");
>while (<F>) {
>	chomp();
>	if (/^$nome/i) {
>		@dados = split (/:/, $_);
>		last;
>	}
>}
>if ($dados[0]) {
>	print "Nome:\t$dados[0]\n";
>	print "End:\t$dados[1]\n";
>	print "Bairro:\t$dados[2]\n";
>	print "Estado:\t$dados[3]\n";
>	print "Fone:\t$dados[4]\n";
>} else {
>	print "Dados indisponíveis.\n";
>}
>

_________________________________________________________________
Chegou o Windows Live Spaces com rede social. Confira 
http://spaces.live.com/



Mais detalhes sobre a lista de discussão Cascavel-pm