Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

How to use perl %hash in BF step?

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;

0 votes



2 answers

Permanent link
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

0 votes


Permanent link
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

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 12,026

Question asked: Jul 25 '14, 2:10 p.m.

Question was seen: 4,105 times

Last updated: Jul 28 '14, 10:11 a.m.

Confirmation Cancel Confirm