----- Original Message ----- From: Pablo Wolter <[EMAIL PROTECTED]> Date: Thursday, March 24, 2005 3:43 pm Subject: Help working/searching fields in 3 files
Hi,
Hello,
I need some ideas because I'm just trying and error programming.
I have some .dat files that come in this format (call this file dat.dat):
#
[...]
I think the main problem with your code, is lack of proper data strcutures which perl offers. You should try a more searchable structure such as a hash, so that there exists common keys/fields betwean each structure. Here is one way you can achive this task:
At the begining I think on hash, but I get confused with the key and that stuff
#!PERL
use warnings; use strict;
# Lets get our dat.dat into a structure my %Dat_Hash; open RD, "dat.dat" or die "ERROR: $!\n";
foreach my $line ( <RD> ){ chomp $line; my @tmp = split ' ',$line; $Dat_Hash{ $tmp[0] } = $line;
} close RD;
# Now lets get the csv stuff my %Csv_Hash;
open RD, "csv.txt" or die "ERROR: $!\n";
foreach my $line ( <RD> ){ chomp $line; my @tmp = split ' ',$line; $Csv_Hash{ $tmp[1] } = $line;
} close RD;
# and now we process pc.txt open RD, "pc.txt" or die "ERROR: $!\n"; my $debug;
foreach my $line ( <RD> ){ chomp $line; print "Match => $line !!!\n" if $Dat_Hash{$line} && $debug; delete $Csv_Hash{$line} if $Dat_Hash{$line}; } close RD;
# Now you have your data in %Csv_Hash print $Csv_Hash{$_},"\n" for keys %Csv_Hash;
Thanks for the ideas, I'll try this aproach and see if works for the job I need to do. What I was thinking to do is to work directly on the csv files, doing a search line by line and delete the lines that don't appear on the dat file but are on the pc.txt. Thanks for the help.
Thanks in advance
-- (o_ Pablo A. Wolter N. //\ Usuario Registrado #284649 V_/_ Linux Debian Sid Kernel 2.6.8
"Pienso....luego instalo Linux....entonces existo."
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
Pablo.
-- (o_ Pablo A. Wolter N. //\ Usuario Registrado #284649 V_/_ Linux Debian Sid Kernel 2.6.8
"Pienso....luego instalo Linux....entonces existo."
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>