in reply to
Generating a list of numbers from other lists
Wow, thanks guy's, amazing amounts of posts trying to help me...
Sorry, jwkrahn and johngg, I just saw your posts now after trying the answers above and posting this with my findings.
Ok, so it seems i might have not explained my self properly and provided an adequate example. Although, you guy's did a great job at the answer.
I decided to go with choroba's example since it was the simplest for me to understand. As a test script it worked. However when i incorporated this into my real script, it didn't work. After some troubleshooting, it appears that the "my ($Key, $Value) = split;" might have something to do with it.
I thought i did a good job at providing "real" code, but i apparantly failed : -)<cr>
So here is my "real code" this codes fits inside a script so this is why I had the "If ($Flag == $TRUE)" in there. (I mention it incase it makes a difference in the end.) this code fits within the if and the }.<cr>
So here is a sample of the real "TmpIPFile":
Source Destination Packets Bytes
15.254.32.120 10.2.9.2 5 504
79.15.122.235 208.43.3.154 21 2092
79.15.122.235 63.245.217.113 21 2232
79.15.122.235 209.15.236.80 10 1310
79.15.122.235 46.37.179.218 34 4065
63.97.127.34 10.2.9.2 4 471
79.15.122.235 63.141.200.24 19 1811
79.15.122.235 72.251.219.10 437 56713
79.15.122.235 96.7.122.206 215 23318
79.15.122.235 209.200.154.225 77 6257
79.15.122.235 64.94.107.23 13 3436
79.15.122.235 64.74.126.22 23 1527
17.149.36.162 10.2.9.3 14 3416
79.15.122.235 184.25.187.120 49 5772
79.15.122.235 205.251.242.166 21963 32615009
79.15.122.235 12.239.198.71 26 2946
79.15.122.235 184.85.247.120 145 18458
79.15.122.235 184.235.49.15 10 2001
79.15.122.235 207.171.163.162 19 1393
79.31.21.75 10.2.9.2 11 3993
209.68.19.130 10.2.9.2 33 15941
79.15.122.235 64.94.107.16 4 1375
79.15.122.235 207.67.0.233 29 3742
72.247.242.235 10.2.9.2 7 3750
79.15.122.235 64.145.92.232 9 2364
79.15.122.235 208.88.180.89 28 4490
79.15.122.235 94.100.188.227 10 1979
17.149.36.15 10.2.9.3 14 3404
79.15.122.235 128.175.60.118 280 15120
65.54.81.34 10.2.9.2 42 23068
79.15.122.235 209.236.72.16 102 9765
79.15.122.235 65.55.33.50 18 5479
79.15.122.235 17.149.36.197 54 7279
67.148.147.64 10.2.9.2 553 274036
79.15.122.235 204.245.63.99 42 9826
79.15.122.235 207.46.206.74 104 10498
67.148.147.65 10.2.9.3 57 39207
17.172.232.80 10.2.9.3 27 6768
79.15.122.235 217.212.238.134 320 43460
8.8.8.8 10.2.9.6 84 8006
79.15.122.235 74.125.226.176 214 46874
79.15.122.235 23.12.158.224 299 30331
79.15.122.235 68.67.159.207 48 13422
79.15.122.235 208.122.28.12 33 2857
Accounting data age is 0w1d
Box#
Here is the "TmpLookingForIPFile" file:
10.2.9.2
10.2.9.3
10.2.9.4
10.2.9.5
And now the script that I used from choroba...:
#!/usr/bin/perl
use warnings;
use strict;
my $FALSE = 0;
my $TRUE = 1;
my $Flag = $TRUE;
my $number_list = "TmpIPFile";
my $looking_for = "TmpLookingForIPFile";
my $DestDevice = "Box";
my %remember;
if ($Flag == $TRUE){
open my $NUMBER_LIST, '<', $number_list or die "$number_list: $!";
while (<$NUMBER_LIST>) {
next if /^sh|^\s*Source|^$DestDevice|^Accounting|^|^$|/; # Sk
+ip text and empty lines
my ($key, $value,) = split;
push @{ $remember{$key} }, $value;
}
close $NUMBER_LIST;
open my $LOOKING_FOR, '<', $looking_for or die "$looking_for: $!";
while (<$LOOKING_FOR>) {
chomp;
for my $value (@{ $remember{$_} }) {
print "$_ $value\n";
# Do your calculations here...
}
}
close $LOOKING_FOR;
}
So in the end, I should be getting the list but instead I get nothing.
Here is the list I would want from this output (p.s. I need the "# Do your calculations here..." part since this will do the calculations that i need within the loop) The Calculations will be done on the Bytes field of the appropriate ip's:
5.254.32.120 10.2.9.2 5 504
63.97.127.34 10.2.9.2 4 471
79.31.21.75 10.2.9.2 11 3993
72.247.242.235 10.2.9.2 7 3750
65.54.81.34 10.2.9.2 42 23068
7.148.147.64 10.2.9.2 553 274036
17.149.36.162 10.2.9.3 14 3416
17.149.36.15 10.2.9.3 14 3404
67.148.147.65 10.2.9.3 57 39207
17.172.232.80 10.2.9.3 27 6768
8.8.8.8 10.2.9.6 84 8006
I hope that it's only a slight modification required to achieve my goal..
Any Takers?