Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://973102]
help
Chatterbox?
[trahulprajapati]: hi
[Eily]: hello trahulprajapati
[trahulprajapati]: how can i use javascript in WWW::Machanize for login to a webpage?

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2017-06-22 15:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (523 votes). Check out past polls.