in reply to Re^3: Loading all files in a dir with use via for loop
in thread Loading all files in a dir with use via for loop

Thanks radiant.matrix,
Thats working with the exception of the error message (forgot the package command in one of the files thus it caused problems (all files are part of main as they were orginally in the main file and only stripped out and put into smaller ones to make reading and editing easier))....
. Specifically, I'd like the eval (prefer eval over the dispatch in this situation), to call nopageerror (which is in the main package). I've tried adding else commands to the if, however, as my luck this week has been, its kicking out with an error (probibily because it not valid, didn't find a ref to useing if-then-else in eval's, but thought I'd try anyway). The reason for calling nopageerror, is to display a useful information in the browser as well as generate special logs that arn't quite as cryptic as the Perl error messages and Apache logs...

What would I have to do to be able to eval the var, if the var is a function, execute it, if not, call the sub routine to issue the error message about the missing function. This is probibily so simple that I'm over looking it...
  • Comment on Re^4: Loading all files in a dir with use via for loop

Replies are listed 'Best First'.
Re^5: Loading all files in a dir with use via for loop
by Delusional (Beadle) on Sep 29, 2005 at 14:09 UTC
    Never mind, problem solved by using or. Geez, did I over look the obvious...

    For those that need it.....
    eval "$PAGE" if main->can($PAGE) or main->nopageerror;


    Thanks again radiant.matrix for the push in the right direction.

      That does work because of the super-low-precedence of 'or'.Actually, it doesn't work. The if wants to evaluate all of the following expression. It's not very readable, thougheither.: someone who doesn't understand the lower-precedence-ness of 'or' (compared to '||', especially). To them it would look like you shouldIt will try to eval $PAGE if one of the two or statements is true. Also, you don't need to specify main-> for nopageerror.

      For clarity, I suggest one of these:

      # whoops, syntax errors, thanks to Roy Johnson ## ( eval "$PAGE" if main->can($PAGE) ) or nopageerror; ## or... #( eval "$PAGE" if main->can($PAGE) ) # or nopageerror; ## or... if ( main->can($PAGE) ) { eval $PAGE } else { nopageerror }

      Updates:

      • 2005-09.Sep-30 : fixed stupid errors as pointed out by Roy Johnson. Don't code without coffee, kids! :-)

      <-radiant.matrix->
      Larry Wall is Yoda: there is no try{} (ok, except in Perl6; way to ruin a joke, Larry! ;P)
      The Code that can be seen is not the true Code
      "In any sufficiently large group of people, most are idiots" - Kaa's Law
        predicate-if is not an operator, it is a statement modifier. It is not part of an expression, so you can't parenthesize it. Your first suggestion is a syntax error.

        Caution: Contents may have been coded under pressure.
        You are correct radiant.matrix. I'm always forgetting the ||/or methods. Simularily I confuse the eq and = and == thus causing scripting errors.... The simplest things are generally the easiest to over look and cause the most problems.