Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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

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?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2015-11-28 04:34 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (737 votes), past polls