perl- read search and replace string from the file

Dear all,
I have a number of files and each file has two sections separated by a blank line. At the top section, I have lines which describes the values of the alphabetical characters,

# s #; 0.123
# p #; 12.3
# d #; -2.33
# f #; 5.68
<blank line>
sssssss
spfdffff
sdfffffff

Now I want "s" should be replaced by 0.123 in last three lines, "d" by -2.33 etc. Number of alphabetical characters vary in each file and also the number of lines below the blank line may vary.
I am seeking for a perl program preferably, to automate text processing.
-regards and thanks,
satti

Please post desired output for this sample data.

dear bartus11 and others,
The desired output would be as :

0.123 0.123 0.123 0.123 0.123 0.123 0.123 
0.123 12.3 5.68 -2.33 5.68 5.68 5.68 5.68 
0.123 -2.33 5.68 5.68 5.68 5.68 5.68 5.68 5.68 

thnx,
satti

Try:

awk '/^#/{a[$2]=$4;next}{n=split($0,b,"");for (i=1;i<=n;i++) printf a[b]" ";printf "\n"}' file
1 Like

Thanks a lot for a working code