Just for fun, we'll refactor it into more idiomatic perl...
Making cosmetic changes to code is not "refactoring."
The only item you listed that actually makes a bit of real difference is:
and that's terrible advice. The filehandle should absolutely be closed. It's a global (package) variable and probably won't go out of scope until the program ends. Leaving it open is an undocumented and probably undesired side-effect.
- We don't need the close - the filehandle will automatically be closed when it falls out of scope.
Oh wait... You also made this subtle yet significant change:
The problem with that is that you made an assumption based on a small bit of sample input. What if the input allows some lines to consist of only two fields? If it does, then you might well want the split to remove a newline from the school name. Granted, it will probably work without the split but recommending its removal without more information is irresponsible.
- Since we're not looking at the end of the line we don't need the chomp at all... so we remove it...
By the way, IMHO, his variable names were just fine for the task at hand. I would have chosen them differently and probably closer to the names you picked but that's largely a matter of style. Style is something we all develop for ourselves. It takes time and we find ourselves making niggling little decisions like whether to use $id_to_fetch or $fetch_id as you seem to have struggled with. Personally, I would have stuck with $fetch_id because I think prepositions in variable names are ugly and cumbersome but it's still a style decision.
Rewriting code just because you can is rarely a good idea. You should always have a good reason for rewriting something. Even with good reason, you should be careful to keep the functionality equivalent unless you're sure it doesn't work.
In other words, if it ain't broke...
</rant>
-sauoq "My two cents aren't worth a dime.";
In reply to Re: Re: Cannot read in multiple lines
by sauoq
in thread Cannot read in multiple lines
by Angel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |