Hi all,
I am in fruit industry and dealing with stock inventory of fruits.
I got 2 files, one file got fruit names (fruit.txt) and other file got the inventory status (status.txt).
Task for me was to check the fruit list and update the inventory status:
Contents of the files:
1st file (fruit.txt):
=====================
rambutan
guava
apple
lychee
durian
2nd File (status.txt):
======================
<data>
<apple>
<In_Stock>true</In_Stock>
</apple>
<orange>
<In_Stock>true</In_Stock>
</orange>
<banana>
<In_Stock>false</In_Stock>
</banana>
<coconut>
<In_Stock>true</In_Stock>
</coconut>
<rambutan>
<In_Stock>false</In_Stock>
</ramputan>
<melon>
<In_Stock>true</In_Stock>
</melon>
<palm>
<In_Stock>true</In_Stock>
</palm>
<guava>
<In_Stock>false</In_Stock>
</guava>
<grapes>
<In_Stock>true</In_Stock>
</grapes>
<jackfruit>
<In_Stock>false</In_Stock>
</jackfruit>
</data>
When comparing the files, need to take one fruit at a time and see if it exists in the status file. If exists then need to check whether <In_Stock> flag is set to true or false. If true then need not do nothing. If false then need to change it to true. If the file does not exist in the status file then append the status file with the fruit info in format:
<fruit>
<In_Stock>true</In_Stock>
</fruit>
I am a novice in PERL with great enthusiasm. I solved the problem but it took nearly 100 lines of code for that. Someone commented that the code is not elegant although it does what it is supposed to do.