perl - Make hash from regex expression patten match -error -
i making hash regex expression. run program below , have check @ end see if hash made ok. keep getting error value., array(0x1a1c740), when should 437768. keys can display ok. didnt split because need key first part of species name. matching.
# "aaaaaaaaaa","aaaaaaaaaa","437768","cryptophyta sp. cr-mal06",0
thanks may give.
use strict; use warnings; open (my $in_fh,"$argv[0]") or die "failed open file: $!\n"; open (my $out_fh, ">genus.txt"); %hash; while ( $line = <$in_fh> ) { # # "aaaaaaaaaa","aaaaaaaaaa","437768","cryptophyta sp. cr-mal06",0 # if ($line =~ m/\"+\w+\"+\,+\"+\w+\"+\,+\"+(\d+)\"+\,+\"+(\w+)+.+/) { $v = $1; $k = $2; $hash{$k} = [$v]; } } if (exists $hash{'cryptophyta'}) { print $out_fh $hash{'cryptophyta'}; } else { print $out_fh "no\n"; } close $in_fh; close $out_fh;
change line:
$hash{$k} = [$v];
to
$hash{$k} = $v;
[$v]
reference array want store scalar.
Comments
Post a Comment