Think about Loose Coupling | |
PerlMonks |
Re: Getting an unknown errorby Athanasius (Archbishop) |
on Apr 23, 2015 at 15:43 UTC ( [id://1124418]=note: print w/replies, xml ) | Need Help?? |
Hello andybshaker, Others have answered your immediate question, but I want to comment on this part of your code:
(I have reformatted it a little to make it clearer.) First, the use of $1 as a loop variable is — well, unusual, to say the least. Normally, $1 contains the first matched string in the last regular expression match. In idiomatic Perl, the variable $_ is used implicitly:
But second, and much more importantly, this foreach loop does literally nothing. You create a lexical variable %columns and fill it with split; then re-create it on the next iteration of the loop; and so on. And when the loop ends, the variable — having been declared within the scope of the loop — goes out of scope and is (eventually) garbage-collected. The contents of the file remain unchanged. And a final point: Please, please get into the habit of using a sane code formatting (indenting) style for nested loops. For example:
Why make your code harder to read than it needs to be? The maintenance programmer who comes to look at the code in six months time may well be you! Hope that helps,
In Section
Seekers of Perl Wisdom
|
|