Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Perl text processing

by vinoth.ree (Monsignor)
on Jun 09, 2014 at 13:19 UTC ( [id://1089267]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 07:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found