in reply to Question about text::csv_xs
getline parses a single line, but if you want to keep the original lines (so that you can determine the lines that appear in both files), then I don't think it is very useful to you. How about this (untested!)?:
use strict; use warnings; use Text::CSV_XS; my ( $h1, $h2 ) = map get_parsed_lines( $_ ), qw( file_1 file_2 ); my %keep = map +( $_ => $h1->{ $_ } ), grep exists $h2->{ $_ }, keys %$h1; sub get_parsed_lines { my $file = shift; my $csv = Text::CSV_XS->new(); my %hash; open my $in, '<', $file or die "Read failed: $!\n"; while ( <$in> ) { $csv->parse( $_ ) or warn "Bad data: $_\n", next; $hash{ $_ } = [ $csv->fields() ]; } close $in or die "Failed to close $file: $!\n"; return \%hash; }
the lowliest monk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Question about text::csv_xs
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 |