How to use perl %hash in BF step?
![](http://jazz.net/_images/myphoto/ac37cd0f817302f1db6c1f7282660abb.jpg)
2 answers
![](http://jazz.net/_images/myphoto/ac37cd0f817302f1db6c1f7282660abb.jpg)
Hi Jirong,
"map" expects an array and returns an array. See:
http://perldoc.perl.org/functions/map.html
It is possible to return a hash by using the "=>" syntax.
"split" is a way of converting a scalar string value into an array by chopping it up at places that match the regulr expression. So generally you would write:
Is "$fh" a file handle? If it is then you need to read from the file handle first:
my $line = <$fh>; #Read a line form the file.
my @array = split (/=|\s+/, $line); # Split the line on equals or spaces.
my %hash = map { get_a_key_for($_) => $_ } @array; # Create a dictionary for each element of the line
I hope this helps,
Simon
"map" expects an array and returns an array. See:
http://perldoc.perl.org/functions/map.html
It is possible to return a hash by using the "=>" syntax.
"split" is a way of converting a scalar string value into an array by chopping it up at places that match the regulr expression. So generally you would write:
Is "$fh" a file handle? If it is then you need to read from the file handle first:
my $line = <$fh>; #Read a line form the file.
my @array = split (/=|\s+/, $line); # Split the line on equals or spaces.
my %hash = map { get_a_key_for($_) => $_ } @array; # Create a dictionary for each element of the line
I hope this helps,
Simon