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
-
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.