It's all about the answers!

Ask a question

How to use perl %hash in BF step?


Jirong Hu (1.5k9295258) | asked Jul 25 '14, 2:10 p.m.
I want to execute the following perl script within a BF step, how shall I write it? It seems doesn't accept %hash.

 my %hash = map { split /=|\s+/; } $fh;

2 answers



permanent link
Simon Washbrook (67216) | answered Jul 28 '14, 3:54 a.m.
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

permanent link
Jirong Hu (1.5k9295258) | answered Jul 28 '14, 10:11 a.m.
Thanks for your reply, Simon.

My question was how to properly write perl variables within the BF steps, as described in this technote. $var have to be written as $$var. So how about %hash? do I need to write it as %%hash?


Thanks
Jirong

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.