in reply to Writing indexed arrays in to an file and then retrieved
the array is populated in the following mannereval(" push \@reg_map${page_counter},\[\"\$var01\",\$var00,\"$var02 +\"\]");
Eek. So you have something like @reg_map00,@reg_map01,@reg_map02,..?
Whenever you are tempted to add a counting suffix to any variable, use an array instead:push @{$reg[$page_counter]}, @var;
Think of eval as a costly subshell under the control of you program in its own sandbox1. Setting that up only to push to an array is overkill, convoluted, difficult to read and maintain.
Whenever you are tempted to use variables using a stem and a suffix, e.g. $some_foo, $some_bar, $some_baz - use a hash instead:
%some = ( foo => ..., bar => ..., baz => ..., ... );
This makes your code cleaner, more readable, more maintainable, and it makes constructs like your eval push unnecessary.
1) Not quite a sandbox proper, since even string eval gets the surrounding lexicals, let alone (package) globals.
|
|---|