Thargor has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to read in two files with Text::CSV_XS and push all the rows that occur in both files onto a hash and output that into another CSV file. I think I am going to need a hash of arrays and make the key to the hash what I am comparing.
So what I am wanting to know is how to read the entire list in from a CSV file? In the documentation on CPAN I haven't been able to tell if the getline($io) command will only return 1 line and if it does how do I keep track of which line of the file I am on? If any of the wise monks could explain how I can efficiently read in a CSV file with Text::CSV_XS it would help out a lot.
Update:I am pretty sure what I need is just to get the lines of 1 file put them all into a hash using my comparison variable as the key to the hash then get the other file of csv lines and push that into the hash there by getting rid of any duplicates. This would work because I know where the data is coming from and know that the key I would be using is definitely unique and it seems as though it would work fairly quickly. I just don't know how to read in an entire csv file cause I am horrible with file i/o.
Update 2: Ok I have everything reading in like it is supposed to, thanks tlm, and have started outputing the data. Since I am just fumbling with this in my spare time and with my virtual total ignorance of perl it can be tough. So, I started using a IO::File handle because that is what the Text::CSV_XS says to use and my information writes to the file but it is all on the same line. My code for outputing is as follows:
So is there something I have doen incorrectly in the output or should I work on my %hashed information? Thanks in advance.my $fh = new IO::File "> output.csv"; foreach my $hash ( %hashed){ if($hashed{$hash}){ $status = $csv->print($fh, $hashed{ $hash }); } } $fh->close;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Question about text::csv_xs
by jZed (Prior) on Apr 27, 2005 at 20:21 UTC | |
|
Re: Question about text::csv_xs
by tlm (Prior) on Apr 27, 2005 at 20:35 UTC | |
by Thargor (Scribe) on May 04, 2005 at 14:13 UTC | |
by tlm (Prior) on May 04, 2005 at 15:10 UTC | |
by Thargor (Scribe) on May 04, 2005 at 17:42 UTC | |
|
Re: Question about text::csv_xs
by Tanktalus (Canon) on Apr 27, 2005 at 23:19 UTC | |
by jZed (Prior) on Apr 27, 2005 at 23:24 UTC | |
|
Re: Question about text::csv_xs
by Thargor (Scribe) on Apr 29, 2005 at 18:25 UTC | |
by jZed (Prior) on Apr 29, 2005 at 19:08 UTC |