[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Omaha.pm] Pulling in a hash via "exec"...FAIL



Dan Linder wrote:
I thought of that but I couldn't find an comments regarding the differences
caused by changing the hash (%fields) to a straight variable ($fields).  I
know Perl doesn't do strict casting of variables, but this still looked odd
to me.

On Thu, Aug 7, 2008 at 9:50 AM, Jay Hannah <jay@jays.net> wrote:
-ponder-   When you eval this
$fields = {
 'FIELD1' => {
               FIRSTNAME => 'Joe',
               LASTNAME => 'Smith'
 }

$fields is a hash reference. But in your first post you were scoping and returning %fields, which is a hash. Hence your version was scoping and returning a hash which had absolutely nothing to do with what your were eval'ing.

My change was scoping a scalar $fields, which the eval turns into a hash reference, and returns that. I assume this is what you meant to do.

The code I'm working on has had an unknown number of programmers over the last five years (most field engineers who hacked the code and submitted an enhancment, not necessiaraly any full-time programmers) so some of the code in it was probably put in and left there because it worked at the time and the permissiveness of Perl allowed for the abuse of variable type casting.  :-)

I need to gather a few more customer generated files to test, but I think changing to the scalar $fields is probably the correct answer.
 
You might want to stick these in the top of your program:
use strict;
use warnings;
use diagnostics;
 
Yes, wonderful additions - unfortunatly I know that Perl will not execute this piece of code due to failures the "use strict" finds so working through them is probably the best solution.  (And if not, I can always wrapper portions of code I can't fix with "no use strict"...sigh)

(I still think eval is evil and you should use Storable. $0.02 -grin-)

Hmmm, this must be a pretty evil program by your measure - it uses eval quite a bit. :-)

Storable looks like a good solution, but the saved files need to be human readable like the Data::Dump output - I searched for a flag in the Storable perldoc but couldn't find one.   (And I don't think that is the intention of Storable anyway - just provide the ability to store a MACHINE readable variable not HUMAN readable...)

Dan

--
"Quis custodiet ipsos custodes?" (Who can watch the watchmen?) -- from the Satires of Juvenal
"I do not fear computers, I fear the lack of them." -- Isaac Asimov (Author)
** *** ***** ******* *********** *************