http://www.perlmonks.org?node_id=369412


in reply to Re: To initialise or not to initialise?
in thread To initialise or not to initialise?

Are you really using global variables? You should be using lexical variables, declared with my, everyhere you can. For example, you can declare the loop variable inside the for statement.
foreach my $item (@array) {

I don't like the style of declaring lexical variables at the top of a function. I much prefer declaring the variable where it is first assigned. It must be a carryover from C where that is the only way to declare variables. But I can understand it.