in reply to Perl text processing

Hi biboshakan first of all welcome to PerlMonks!

i've been assigned to write something for text processing.

This is your task, first try yourself, if you struggle come here with the code you tried, we will help you better.


All is well

Replies are listed 'Best First'.
Re^2: Perl text processing
by biboshakan (Initiate) on Jun 12, 2014 at 07:28 UTC

    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"; } } }