Count duplicate values in hash of an array

matrix154

I'm generating a hash and pushed that hash in an array. The array at the end shows like

$VAR1 = [
          {
            'Count' => 1,
            'maint_wf' => 'WFblabla',
            'lines' => {
                         'line1' => {
                                      'ort' => 'city_x',
                                      'lbz' => 'L1city_x'
                                    }
                       },
            'receive_date' => 'Di, 3 Sep 2013 12:16:43 +0200',
            'maint_date' => '02.09.2013',
            'calendar' => {
                            'dtend' => '20130902T0530',
                            'dtstart' => '20130902T0100'
                          }
          },
          {
            'Count' => 3,
            'maint_wf' => 'WFbla',
            'lines' => {
                         'line3' => {
                                      'ort' => 'city1',
                                      'lbz' => 'L1_city1'
                                    },
                         'line1' => {
                                      'ort' => 'city2',
                                      'lbz' => 'L1_city2'
                                    },
                         'line2' => {
                                      'ort' => 'city2',
                                      'lbz' => 'L2_city2'
                                    }
                       },
            'receive_date' => 'Mi, 4 Sep 2013 08:56:35 +0200',
            'maint_date' => '03.09.2013',
            'calendar' => {
                            'dtend' => '20130903T0530',
                            'dtstart' => '20130903T0300'
                          }
          },
          ...
        ];

How can I count the duplicate values of the key 'ort' (i.e. how many 'ort' => 'city2' exist?) and then just display the corresponding values of key 'lbz'?

choroba

Creating a hash that counts the possible lbz values for each ort value might help you:

#!/usr/bin/perl
use warnings;
use strict;

use Data::Dumper;

my $arrR = [
            {
                'Count' => 1,
       # ...  
           ];

my %ort;
for my $hashR (@$arrR) {
    my @lines = values %{ $hashR->{lines} };
    for my $line (@lines) {
        $ort{ $line->{ort} }{ $line->{lbz} }++;
    }
}
print Dumper \%ort;

Output:

$VAR1 = {
          'city2' => {
                       'L1_city2' => 1,
                       'L2_city2' => 1
                     },
          'city_x' => {
                        'L1city_x' => 1
                      },
          'city1' => {
                       'L1_city1' => 1
                     }
        };

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

count duplicate values in array using angularjs

分類Dev

Java Hash map / Array List Count distinct values

分類Dev

Check an array for duplicate values, get value and get count

分類Dev

Swift 2 count duplicate in array

分類Dev

Unique count of array values

分類Dev

Finding count of duplicate values and ordering in a Pandas dataframe

分類Dev

PHP - Count the values of an array not the keys?

分類Dev

Ruby - How to invert a Hash with an array values?

分類Dev

How to remove duplicate values from an array in PHP

分類Dev

How to remove duplicate values from an array in PHP

分類Dev

Remove duplicate values from Array of Dictionaries

分類Dev

best way to group adjacent duplicate values into an array

分類Dev

MySQL to PostgreSQL - Find in array, and count array values

分類Dev

How to get the count of keys for values in a hash map using lambda

分類Dev

How to convert array of hashes into a single hash and count repeated items?

分類Dev

How to count all values in a multidimensional array?

分類Dev

How to count items in arrays of values in an array of hashes

分類Dev

Return count of values in array not divisible evenly by 2

分類Dev

AWS DynamoDB Scan and FilterExpression using array of hash values

分類Dev

How to add specific values from array list to the Hash map?

分類Dev

Finding values from array in hash key and return counts of zero

分類Dev

PHP - How to remove duplicate values from array (compare 2 arrays)

分類Dev

Count duplicate dates occurrences

分類Dev

Access (and count) just object values from Postgres JSONB array of objects

分類Dev

Count the number of non zero values in a numpy array in Numba

分類Dev

How to get the count of repeated key values of array object of consecutive elements?

分類Dev

Change Duplicate values index

分類Dev

Return sorted unique values from array, but if count is equal, return values in order

分類Dev

Why angularjs(ng-repeat) allowing to add duplicate record at first time if the input array values are integer types

Related 関連記事

  1. 1

    count duplicate values in array using angularjs

  2. 2

    Java Hash map / Array List Count distinct values

  3. 3

    Check an array for duplicate values, get value and get count

  4. 4

    Swift 2 count duplicate in array

  5. 5

    Unique count of array values

  6. 6

    Finding count of duplicate values and ordering in a Pandas dataframe

  7. 7

    PHP - Count the values of an array not the keys?

  8. 8

    Ruby - How to invert a Hash with an array values?

  9. 9

    How to remove duplicate values from an array in PHP

  10. 10

    How to remove duplicate values from an array in PHP

  11. 11

    Remove duplicate values from Array of Dictionaries

  12. 12

    best way to group adjacent duplicate values into an array

  13. 13

    MySQL to PostgreSQL - Find in array, and count array values

  14. 14

    How to get the count of keys for values in a hash map using lambda

  15. 15

    How to convert array of hashes into a single hash and count repeated items?

  16. 16

    How to count all values in a multidimensional array?

  17. 17

    How to count items in arrays of values in an array of hashes

  18. 18

    Return count of values in array not divisible evenly by 2

  19. 19

    AWS DynamoDB Scan and FilterExpression using array of hash values

  20. 20

    How to add specific values from array list to the Hash map?

  21. 21

    Finding values from array in hash key and return counts of zero

  22. 22

    PHP - How to remove duplicate values from array (compare 2 arrays)

  23. 23

    Count duplicate dates occurrences

  24. 24

    Access (and count) just object values from Postgres JSONB array of objects

  25. 25

    Count the number of non zero values in a numpy array in Numba

  26. 26

    How to get the count of repeated key values of array object of consecutive elements?

  27. 27

    Change Duplicate values index

  28. 28

    Return sorted unique values from array, but if count is equal, return values in order

  29. 29

    Why angularjs(ng-repeat) allowing to add duplicate record at first time if the input array values are integer types

ホットタグ

アーカイブ