in reply to Get all hash value into array

G'day Magnolia25,

Here's yet another way to do this.

#!/usr/bin/env perl use strict; use warnings; my $VAR1 = { ... as per your OP ... }; my (@all_states, @comment_states); for (map values %$_, values %$VAR1) { my ($state, $comment) = ('', 0); for (@$_) { $state = substr $_, 11 if 0 == index $_, 'state_name='; $comment = 1 if 0 == index $_, 'comments='; } push @all_states, $state if $state; push @comment_states, $state if $comment; } use Data::Dump; dd \@all_states; dd \@comment_states;

Output:

["Alaska", "Puerto Rico", "Washington", "West Virginia"] ["Washington", "West Virginia"]

That handles the words '"comments" is present'; however, your example output suggests you want '"comments" is absent'. Changing if to unless in the second push:

push @comment_states, $state unless $comment;

And the output becomes:

["West Virginia", "Washington", "Puerto Rico", "Alaska"] ["Puerto Rico", "Alaska"]

I'll leave you to decide which you actually want. :-)

— Ken