Beg to differ, %PhoneBook is lexical, but it's declared lexically for the scope of the entire program (at the top of the page).
Yes, there are betters ways to do it! dmtelf, I would definitely try something like this:
our %PhoneBook = &ReadPhoneBookFile(); sub ReadPhoneBookFile { my %TempBook; ... some stuff ... return %TempBook; }
This would have been much more clearer, and our* is the best keyword for global variables like that (a variable used between subroutines without explicitly being passed). HTH :-)
Alakaboo
* I should clarify this. use vars has been somewhat depreciated in favor of our since Perl5.6.0. Since it will no doubt be used prevalently henceforth, and in Perl6, I make it a general rule to use it. If you're running an older version of Perl, you'll need to do:
use vars qw(%PhoneBook); %PhoneBook = &ReadPhoneBookFile();It's just cleaner to use our! (thanks tilly, ya beat me to it!)
In reply to RE: RE: Data extraction from hash problem
by mwp
in thread Data extraction from hash problem
by dmtelf
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |