I have a request for some advice on how to approach this script I want to write in Perl. Basically I have a file that looks like :
id: 1
Relationship: ""
name: shelby
pet: 1
color:4
There are certain keywords such as pet and color that have numbers after then. I want to be able to take in a file and look for these keywords (there are 5 or 6 of them) and then change the number to the word that number corresponds to. That is to say for the keyword “Pet”—> 0 =dog, 1 = cat, 2=fish. And for the keyword “color” 0 = red, 1=blue,2=purple,3=brown,4=white. The script should find and change these numbers. The goal should be an output file that looks like:
id: 1
Relationship: ""
name: shelby
pet: cat
color:white
I’ve been struggling with how to do this for a while. I looked up online maybe I could do an array of hashes or something but I’m relatively new to Perl and don’t know exactly how to even approach this problem…. Any advice would be much appreciated!
Thanks
Usage:
script.pl file.txt > output.txt