in reply to add values with hash
outputs#!/usr/bin/perl use strict; use warnings; use Data::Dumper; $Data::Dumper::Indent = 1; $/ = q{monkey}; my %hash; while (<DATA>){ my ($country, $fox_hour) = /forest\s+(\w+).*-fox\s+(\d{4})/s; next unless $country; push @{$hash{$country}}, $fox_hour; } print Dumper \%hash; __DATA__ forest France -wolf -toad -fox 1350 monkey land -dog -cat -slug forest France -deer -swan -fox 1426 monkey forest USA -deer -swan -fox 1560 monkey
update: added link$VAR1 = { 'France' => [ '1350', '1426' ], 'USA' => [ '1560' ] };
|
|---|