http://qs1969.pair.com?node_id=205742


in reply to Data structure assistance

On the basis of what you've told us (which as George_Sherston said, isn't enough to make a good judgement), I think tadman's method is good except that it means that you need both the ip and the domain name to access the timings. As many ISP's use a single ip to serve several domain names, retaining both peices of information is necessary, but it would be more convenient to only use the domain name for access to the data structure.

If, in the context of your application, you need/want to use the datastructure to lookup the ip associated with a given domain name then a structure like this might be better.

my %data; while ( more data ) { my ($ip,$domain,@times) = readNextChunkOfData(); $data{$domain}{'ip'}= $ip; $data{$domain}{'seconds'} = \@times; # the next line isn't necessary, but could be convenient # IF YOU KNOW YOUR IP/DOMAIN NAME PAIRS ARE UNIQUE. # for doing domain-from-ip lookups. $data{$ip}{'domain'} = $domain; }

That way you can use these lines to lookup the ip from domain or vice versa

my $domain = $data{$ip}{'domain'};

my $ip = $data{$domain}{'ip'};

and this to access the times individually.

 print @{$data{$domain}{'seconds'}}[3]; # 4th timing.

Or something like this to access them in sequence.

... foreach my $time ( @{$data{$domain}{'seconds'}} ) { print $time; }

Note: Some of the punctation in this post is redundant, but I was trying for clarity


Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!