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.

In reply to Re: Counting elements in array of cases by 1nickt
in thread Counting elements in array of cases 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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.