Tanalis has asked for the wisdom of the Perl Monks concerning the following question:
These categorisation rules change periodically, and hence I've created a rules file to perform the categorisation and return a suitable category and reason to the calling sub.
My problem: I'm struggling to have eval return anything. According to the docs:
In both forms, the value returned is the value of the last expression evaluated inside the mini-program; a return statement may be also used, just as with subroutines.
.. but that doesn't seem to work for me.
A typical rule might look like the following, where $abs_diff and $source are defined within the sub performing the eval:
return( "A", "Cat A" ) if $abs_diff < 75_000 and $source eq "ICE";
I've tried the following:
and# process analysis rules foreach( @$analysis_rules ) { eval $_; }
among a bunch of variations without luck.# process analysis rules foreach( @$analysis_rules ) { my( $cat, $comment ) = eval $_; return( $cat, $comment ) if $cat and $comment; }
Can anyone see where I'm going wrong?
Thanks in advance ...
-- Foxcub
#include www.liquidfusion.org.uk
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Returning data from an eval
by Zaxo (Archbishop) on Aug 02, 2005 at 07:47 UTC | |
Re: Returning data from an eval
by holli (Abbot) on Aug 02, 2005 at 09:15 UTC | |
by Tanalis (Curate) on Aug 02, 2005 at 09:42 UTC | |
Re: Returning data from an eval
by anonymized user 468275 (Curate) on Aug 02, 2005 at 10:26 UTC | |
Re: Returning data from an eval
by tlm (Prior) on Aug 02, 2005 at 13:51 UTC |