maheshkumar has asked for the wisdom of the Perl Monks concerning the following question:
Can I find the average number of hops that appear for a particular country example in the following file, the China appears with different hops e.g. 20 hops or 12 hops. So is it possible that i can find the average
So far what I am doing is to print only the lines where China appears along with the hops
use Locale::Country; open my $in, '<', 'num_traces' or die $!; open my $out, '>', 'analysis' or die $!; my @names; my $value = 0; my $value_1 = 0; while ( my $line = <$in>) { @names = all_country_names(); if ($line =~ /China\s\d+\shops/m) { print {$out} "$line\n"; $value++; } }
Any thoughts on this? The Text file looks like the following
Trace for 216.137.61.109 - Seattle -United States 10 hops Trace for 192.168.178.1 - 1 hops Trace for 8.8.8.8 - Mountain View -United States 8 hops Trace for 92.123.72.112 - -Europe Trace for 62.41.85.112 - -Unit +ed Kingdom Trace for 213.155.157.35 - -United Kingdom 9 hops Trace for 216.137.63.227 - Seattle -United States 12 hops Trace for 77.75.76.22 - -Czech Republic 9 hops Trace for 80.237.208.84 - Höst -Germany 8 hops Trace for 208.67.222.222 - San Francisco -United States Trace for 19 +3.93.125.43 - Paris -France Trace for 218.30.82.201 - Beijing -Ch +ina Trace for 91.203.186.13 - -France Trace for 59.53.86.5 - Bei +jing -China 21 hops Trace for 217.72.203.5 - -Germany 9 hops Trace for 123.235.38.123 - Jinan -China Trace for 174.129.215.122 - + Ashburn -United States 30 hops Trace for 77.75.72.22 - Ricany -Czech Republic 30 hops Trace for 123.235.39.126 - Jinan -China 18 hops Trace for 123.235.43.75 - Jinan -China 17 hops Trace for 122.226.213.92 - Yongkang -China 21 hops Trace for 60.28.178.50 - Tianjin -China 19 hops Trace for 60.29.252.89 - Tianjin -China 16 hops Trace for 209.85.227.101 - Mountain View -United States 10 hops Trace for 209.85.148.101 - Mountain View -United States 7 hops Trace for 218.30.66.7 - Beijing -China 19 hops Trace for 204.93.163.233 - Chicago -United States 30 hops Trace for 222.88.95.14 - Beijing -China 30 hops Trace for 124.225.135.224 - -China Trace for 204.9.177.195 - San +Francisco -United States 30 hops Trace for 211.100.56.204 - Beijing -China 21 hops Trace for 193.93.124.172 - Paris -France 30 hops Trace for 122.218.102.11 - Osaka -Japan 18 hops Trace for 202.58.48.1 - -Australia 30 hops Trace for 202.58.49.1 - -Australia 30 hops Trace for 87.248.210.185 - London -United Kingdom Trace for 87.248.2 +01.77 - -Italy Trace for 95.140.237.60 - -United Kingdom 7 hops Trace for 69.175.33.75 - Chicago -United States 18 hops Trace for 122.228.242.240 - Beijing -China 30 hops Trace for 121.207.229.250 - Fuzhou -China Trace for 60.28.213.151 - + Tianjin -China Trace for 61.155.199.240 - Beijing -China 30 hops Trace for 114.80.182.250 - Shanghai -China Trace for 65.203.229.217 +- Seattle -United States 16 hops Trace for 65.242.27.136 - Seattle -United States 16 hops Trace for 67.195.160.134 - Sunnyvale -United States 30 hops Trace for 67.221.32.222 - Rancho Cucamonga -United States 18 hops Trace for 204.11.109.24 - Emeryville -United States Trace for 70.42. +35.80 - Atlanta -United States 30 hops Trace for 198.41.0.4 - Sterling -United States 30 hops Trace for 92.123.64.26 - -Netherlands 10 hops Trace for 195.59.150.146 - -United Kingdom Trace for 92.123.69.75 - + -Europe 6 hops Trace for 92.122.212.42 - -Europe Trace for 92.123.66.243 - -Eur +ope Trace for 77.67.20.43 - -Netherlands 9 hops Trace for 121.14.24.252 - Guangzhou -China 30 hops
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Finding average from numbers appearing in a file
by davido (Cardinal) on Aug 05, 2012 at 01:48 UTC | |
by maheshkumar (Sexton) on Aug 05, 2012 at 09:35 UTC | |
by Athanasius (Archbishop) on Aug 05, 2012 at 09:58 UTC | |
|
Re: Finding average from numbers appearing in a file
by 2teez (Vicar) on Aug 05, 2012 at 05:15 UTC | |
|
Re: Finding average from numbers appearing in a file
by trizen (Hermit) on Aug 05, 2012 at 08:44 UTC |