in reply to Re^3: Understanding variable scope in perl
in thread Understanding variable scope in perl

No worries!

Actually, no, you don't need to prefix everything with "main::", though that would certainly be one way to go about it.

Better to make global only the few things that you really want to have global, by putting them at the top of your program, and prefixing them with my:

# My global variables (Actually, these should really be constants...) my $boiling_point_fahrenheit = 212; my $known_other_universes = 0; my $answer_to_everything = 42;
You should make everything else local (actually lexically-scoped) with my prefixing it.

A good test of whether a given variable should be global or not:  if you were convert most or all of the subroutines in the program into separate packages, and import them to the main program as objects, would the variable be one that you'd like to retain in the main program (global!), or pass to the constructor or one of the methods of some object? (lexical!)

So, go back and fix all of the errors that you get, and then let me know:  what kind of output do you get now??