I have a data set which has a list of user agents and devices corresponding to those UAs. There is another data set that has other data along with the User Agents. I need a way to identify the devices in that data.
So, I’ll have to map the UAs in the two files and then get the corresponding device info from the file that has the list. I’ve gotten as far as making a list of UAs in a hash from the first file and matching this with the UA in the data file. How do I get the corresponding information from the first file that has the device info again and write it to a file?
#!/usr/bin/perl
use warnings;
use strict;
our $inputfile = $ARGV[0];
our $outputfile = "$inputfile" . '.devidx';
our $devid_file = "devid_master"; # the file that has the UA and the corresponding device info
our %ua_list_hash = ();
# Create a list of mobile user agents in the devid_master file
open DEVID, "$devid_file" or die "can't open $devid_file";
while(<DEVID>) {
chomp;
my @devidfile = split /\t/;
$ua_list_hash{$devidfile[1]} = 0;
}
open IN,"$inputfile" or die "can't open $inputfile";
while(<IN>) {
chomp;
my @hhfile = split /\t/;
if(exists $ua_list_hash{$hhfile[24]}) {
# how do I get the rest of the columns from the devidfile, columns 2...10?
}
}
close IN;
Or is there a better way to do this is Perl? That is always welcome :).
When building the first lookup hash, couldn’t you store a reference to the other column data as the hash value, rather than just 0?
Note: I’ve not tested this.