Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Data structure assistance

by BrowserUk (Patriarch)
on Oct 16, 2002 at 15:23 UTC ( #205742=note: print w/replies, xml ) Need Help??


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!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2022-08-09 20:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?