EDIT: added for loop that removes quotes from beginning and end of items in @data
Usage: perl my_program.pl input_file
Prints:#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %data; { local $/ = ''; while (<>) { my ($key, @data) = split /\n/; for (@data) { s/^"//; s/"$//; } $data{$key} = \@data; } } $Data::Dumper::Indent=1; print Dumper \%data;
(The output is a little messy due to the long key names.)$VAR1 = { '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' ], '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' ] };
EDIT: Used Indent to Data::Dumper to clean up output from Dumper as noted by jdporter
In reply to Re: How to Map a scalar to a key that is an array?
by Cristoforo
in thread How to Map a scalar to a key that is an array?
by symgryph
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |