Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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!

In reply to Re: Data structure assistance by BrowserUk
in thread Data structure assistance by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-25 14:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found