perlquestion
Tanalis
I'm currently working on a script to performs auto-categorisation of data elements based on rules generated from their characteristics.
<p>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.
<p>My problem: I'm struggling to have eval return anything. According to the docs:
<p><em>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.</em>
<p>.. but that doesn't seem to work for me.
<p>A typical rule might look like the following, where <code>$abs_diff</code> and <code>$source</code> are defined within the sub performing the <code>eval</code>:
<code>
return( "A", "Cat A" ) if $abs_diff < 75_000 and $source eq "ICE";
</code>
<p>I've tried the following:
<code>
# process analysis rules
foreach( @$analysis_rules ) {
eval $_;
}
</code>
and
<code>
# process analysis rules
foreach( @$analysis_rules ) {
my( $cat, $comment ) = eval $_;
return( $cat, $comment ) if $cat and $comment;
}
</code>
among a bunch of variations without luck.
<p>Can anyone see where I'm going wrong?
<p>Thanks in advance ...
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-189756">
<P>-- [189756|Foxcub]
<BR><TT>#include [http://www.liquidfusion.org.uk|www.liquidfusion.org.uk]
</TT></P>
</div></div>
<b>Update:</b> Fixed a typo in the rule - thanks to [holli] for pointing that out :)