Using eval() for subroutine unwind 
Author Message
 Using eval() for subroutine unwind

The following snippet of code is a trivial example of how I am attempting to
use eval to support a level of indirection in a validation function.  
Essentially, I would like to be able to call the ValidateField subroutine from
another subroutine.  If the validation fails, I'd like to be able to have the
ValidateField routine force an immediate return _by the caller_.  E.g. in
this case, main calls TestVal calls ValidateField.  Iff validation fails, I'd
like for TestVal to return (without having to actually test any return values
directly with boolean logics).

I've tried several variations on this theme with no success.  This particular
attempt returns the following error message

  Bad label: _EVAL_ at (eval) line 1.

and the perl script terminates.  I need a 4.036 applicable solution, not just perl
5.0, since I'm also using and heavily entrenched in sybperl.

# ===================================================================
#  ValidateField : Validate the content of a required field.
# ===================================================================

sub ValidateField
    local($value, $segment, $fieldNumber, $fieldDescription);

    if ( $value eq "NULL" || $value eq "" )
        $message = "Required field $fieldNumber [$fieldDescription] for the "
                 . "$segment segment is null.";

        print $message, "\n";

        return 'return';



sub TestVal

    eval &ValidateField("$value", "ORC", 1, "set number");

    print "Still in TestVal\n";


Mark A. Scarton, ABD                 | Sunquest Information Systems
801/278-7597, fax 278-0192           | 4505 S. Wasatch Blvd Suite 100


Sun, 30 Mar 1997 19:45:17 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Test for eval() without using eval() ??

2. eval weirdness in perl 4: subroutine parameters?

3. eval - subroutine invocation

4. subroutine in eval with broken pipe

5. eval() and Subroutines

6. Eval subroutines left afterwards: BUG or FEATURE?

7. Subroutines in an eval'ed user-script

8. s// using lexicals and refs in an eval'ed string

9. using here document with eval fails

10. Using eval to iterate over a set of Perl variables

11. Using eval

12. Using Eval Statement To Trap Module Not Present Fatal Error


Powered by phpBB® Forum Software