Hello Monks

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:

my $fh = new IO::File "> output.csv"; foreach my $hash ( %hashed){ if($hashed{$hash}){ $status = $csv->print($fh, $hashed{ $hash }); } } $fh->close;
So is there something I have doen incorrectly in the output or should I work on my %hashed information? Thanks in advance.


In reply to Question about text::csv_xs by Thargor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.