Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: how to remplace a names in a file by keys with hashby Cristoforo (Curate) |
on Apr 27, 2018 at 22:21 UTC ( [id://1213710]=note: print w/replies, xml ) | Need Help?? |
Hello
Your program is full of errors, some of which would have been caught if you had at the top of your program: Rather than going through your program to note the errors and some useless statements, I will post a correct program and you will see how it should look. Note that it does not loop through the keys like you do. And it only opens the file for reading once (the main loop). As for what's inside your while loop, there doesn't seem to be any reason for the different actions you have taken. Most don't make sense. Instead of using the default variable '$_' to read in the input in the while loop, I assigned the line being read to '$line' and this was just for clarity for this example. If I were writing the program myself, I would've probably relied on the default variable '$_' instead. Since I am using 'strict', I have to declare all the variables (with my ...) when they are first mentioned.
In Section
Seekers of Perl Wisdom
|
|