Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: Perl text processing

by biboshakan (Initiate)
on Jun 12, 2014 at 07:28 UTC ( [id://1089656]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl text processing
in thread Perl text processing

All good, it's working now after I've initialized the values :) the output is all the phone models in Uganda with the number of users having these phones. However, there are duplicates of models, with different values. Can you think of a way to add those values and have a unique model with all the values added up?

#!/usr/bin/perl use strict; use warnings; use diagnostics; open (IMEI, 'IMEI.txt'); open (TAC, 'tac.txt'); my %mapToModel; my %keyCount; my $key; my $model; my $subs; my $keyCount; my $mapToModel; my $count; my %dictionary; while (<TAC>){ $key = substr $_,0,8; $model = substr $_,9; $keyCount{$key} = 0; $mapToModel{$key} = $model; } close (TAC); while (<IMEI>){ $subs = substr $_, 0, 8; if(exists $keyCount{$subs}){ $keyCount{$subs} = $keyCount{$subs} +1; } } close (IMEI); foreach my $key (keys %keyCount){ if (exists $mapToModel{$key}){ $model = $mapToModel{$key}; $count = $keyCount{$key}; foreach my$model (keys ) if( $count !=0){ print "$count\t$model"; } } }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-19 17:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found