Hi, welcome to Perl, the One True Religion. There is more than one way to do it. You should use a database for this.
If you install DBD::SQLite, the Perl driver for sqlite, you get, as the doc says, "a Perl DBI driver for SQLite, that includes the entire thing in the distribution. So in order to get a fast transaction capable RDBMS working for your perl project you simply have to install this module, and nothing else."
In the example below, I simply create a database from the data, and then use the SQLite client on my computer to run a query. You could of course extend the Perl script to run the query after loading the data (and if so, you may not need to write a DB file at all, see :memory: as a database name) ... adding such queries to the script is left as an exercise for the reader.
$ cat 11106779.pl
use strict;
use warnings;
use DBI;
my @AoH = ({
targetL => 'foisonnement',
origin => 'AMG',
count => '1',
}, {
targetL => 'foisonnement',
origin => 'IDBR',
count => '1',
}, {
origin => 'IWWF',
targetL => 'gonfler',
count => '1',
}, {
origin => 'IWWF',
targetL => 'due',
count => '1',
}, {
origin => 'IWWF',
targetL => 'due',
count => '1',
});
my $dbh = DBI->connect('dbi:SQLite:dbname=11106779.db','','', { RaiseE
+rror => 1 });
$dbh->do('create table data(targetL varchar(32), origin varchar(16))')
+;
my $sql = 'insert into data (targetL, origin) values (?, ?)';
my $sth = $dbh->prepare($sql);
$sth->execute($_->{targetL}, $_->{origin}) for @AoH;
__END__
$ perl 11106779.pl
( ^ note no output; no errors )
$ sqlite3 11106779.db
SQLite version 3.24.0 2018-06-04 14:10:15
Enter ".help" for usage hints.
sqlite> .headers on
sqlite> select origin, targetL, count(origin) count from data group by
+ origin, targetL order by count desc;
origin|targetL |count
IWWF |due |2
AMG |foisonnement|1
IDBR |foisonnement|1
IWWF |gonfler |1
Hope this helps!
The way forward always starts with a minimal test.
-
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.