Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Merging data

by Limbic~Region (Chancellor)
on May 29, 2012 at 19:50 UTC ( #973102=note: print w/ replies, xml ) Need Help??


in reply to Merging data

lkenefic,
Let's break the problem down in pieces. For ease of explanation, I am assuming CSV files rather than .xls/.xlsx.

#!/usr/bin/perl use strict; use warnings; use Text::CSV_XS; my $file = $ARGV[0] or die "Usage: $0 <input_file>"; my $csv = Text::CSV_XS->new({binary => 1}) or die "Unable to instantia +te CSV object: ", Text::CSV_XS->error_diag(); open(my $fh, '<', $file) or die "Unable to open '$file' for reading: $ +!\n"; while(my $row = $csv->getline($fh)) { # Do something with $row }

That code doesn't do anything useful by itself, but it lays the foundation for processing a CSV row by row. Now consider the following incomplete snippet.

my %lookup; # The hash that maps "in-house" to "different" and vice v +ersa while (my $in_house_row = $csv->getline($fh)) { my $sample_name = $in_house_row->[0]; next if ! defined $lookup{$sample_name}; }

The above snippet shows how to skip rows that do not have a common value between the two files. I do not expect this to solve your problem. I have completely left out the "merge" portion because I do not know what you mean. This should help you articulate exactly what problem you are having as well as demonstrate it with code and real data. You might even want to hand construct the simplest of examples with the expected output.

Cheers - L~R


Comment on Re: Merging data
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://973102]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2014-09-17 04:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (57 votes), past polls