Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

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

Next to the fine comments already given, I suggest using a stream (as already suggested) instead of reading the whole data into a list and add a parsing filter (RFC7111 defines CSV fragments).

Assuming you only require fields 7 and 31 and the rest is not interesting:

#!/usr/bin/perl use 5.18.3; use warnings; use Data::Peek; use Text::CSV_XS qw( csv ); my %ipURL; csv ( in => *DATA, out => undef, fragment => "col=7;31", on_in => sub { push @{$ipURL{$_[1][0]}} => $_[1][1]; }, ); DDumper \%ipURL; __END__ 1,2,3,4,5,6,192.168.102.120,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22 +,23,24,25,26,27,28,29,30,"autodiscover-s.outlook.com/",32 1,2,3,4,5,6,192.168.102.120,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22 +,23,24,25,26,27,28,29,30,"outlook.office365.com/",32 1,2,3,4,5,6,192.168.101.208,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22 +,23,24,25,26,27,28,29,30,"logmeinrescue.com/",32 1,2,3,4,5,6,192.168.101.208,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22 +,23,24,25,26,27,28,29,30,"logmeinrescue.com/",32

--->

{ '192.168.101.208' => [ 'logmeinrescue.com/', 'logmeinrescue.com/' ], '192.168.102.120' => [ 'autodiscover-s.outlook.com/', 'outlook.office365.com/' ] }

As a side note: if a hostname appears more than once for the same IP, using a hash instead of a list might be more memory-friendly and easier to consume:

my %ipURL; csv ( in => *DATA, out => undef, fragment => "col=7;31", on_in => sub { $ipURL{$_[1][0]}{$_[1][1]}++ }, ); DDumper \%ipURL;

-->

{ '192.168.101.208' => { 'logmeinrescue.com/' => 2 }, '192.168.102.120' => { 'autodiscover-s.outlook.com/' => 1, 'outlook.office365.com/' => 1 } }

Enjoy, Have FUN! H.Merijn

In reply to Re: Hash Search is VERY slow by Tux
in thread Hash Search is VERY slow by rtjensen

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 scrutinizing the Monastery: (8)
As of 2024-04-18 10:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found