So I'm trying to make a hash of arrays based on a regex inside a foreach.
I'm getting some file paths, and they are of the format:
longfilepath/name.action.gz
so basically there will be files with the same name but diffent actions, so I want to make a hash with keys of name that are arrays of actions. I'm apparently doing something wrong as I keep getting this error when I run the code:
Not an ARRAY reference at ....the file I'm writing in
Which I don't get since I'm checking to see if its set, and if not declaring it as an array. I'm still getting used to perl, so I'm guessing my problem is something simple.
I should also say, that I've verified my regex is generating both the 'name' and 'action' strings properly so the problem is definitely in my foreach;
Thanks for your help. :)
My code is thus.
my %my_hash;
my $file_paths = glom("/this/is/mypath/*.*\.gz");
foreach my $path (@$bdr_paths){
$path =~ m"\/([^\/\.]+)\.([^\.]+)\.gz";
print STDERR "=>".Dumper($1)."\n\r";
print STDERR "=>".Dumper($2)."\n\r";
#add the entity type to a hash with the recipe as the key
if($my_hash{$1})
{
push($my_hash{$1}, $2);
}
else
{
$my_hash{$1} = ($2);
}
}