Hi,
Using the data from your OP, the above code prints:
Is that really what you wanted? Your original post statedarn:aws:iam::12345678901:role/Role2-Role2,"Alexa for Business" arn:aws:iam::11111111111:role/ADFS-MyRoleName,"Alexa for Business"
If what you want is what you said you want, I would use:
Output:use strict; use warnings; use feature 'say'; use List::Util 'max'; my %count; local $/ = "arn:aws:iam::"; while (my $line = <DATA>) { chomp $line; $line =~ s!$/!! if $. == 1; next if $line eq ''; my ($key, @values) = split(/\n/, $line); $count{$key} = scalar @values; } my @keys = keys %count; my $longest = max map { length } @keys; for my $key (sort @keys) { say sprintf("%-${longest}s : %3d", $key, $count{$key}); } __DATA__ arn:aws:iam::11111111111:role/ADFS-MyRoleName "Alexa for Business" "AWS Certificate Manager" "AWS Certificate Manager Private Certificate Authority" "AWS Amplify" "Manage - Amazon API Gateway" "AWS App Mesh" "Amazon AppStream 2.0" "AWS AppSync" "Amazon Athena" "AWS Auto Scaling" arn:aws:iam::12345678901:role/Role2-Role2 "Alexa for Business" "AWS Certificate Manager" "AWS Certificate Manager Private Certificate Authority" "AWS Amplify" "Manage - Amazon API Gateway" "Application Auto Scaling" "AWS App Mesh" "Amazon AppStream 2.0" "AWS AppSync"
11111111111:role/ADFS-MyRoleName : 10 12345678901:role/Role2-Role2 : 9
Hope this helps!
In reply to Re^4: How to Map a scalar to a key that is an array?
by 1nickt
in thread How to Map a scalar to a key that is an array?
by symgryph
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |