in reply to Dynamically create Packages

It seems that kyle understood what you meant, so I'm sure that I must be missing something, but—what does it mean to not be ‘usable’? I tried running your snippet and, once I defined sub _get_package_name { return $_[0] }, it didn't complain for me. Do you get a complaint, or is it only later that anything bad happens?

UPDATE: Whoops, I didn't use English;, so that $EVAL_ERROR was false while $@ was not.

Replies are listed 'Best First'.
Re^2: Dynamically creat Packages
by Herkum (Parson) on Nov 04, 2008 at 21:23 UTC

    Add this line, after the eval "use $package" statement. (Note: You did add a use strict and use English to your script right?).

    warn "use error: " . $EVAL_ERROR . "\n";

    It should complain twice about not being able to find the package. Once for each call. If you add a third call it would complain a third time, etc... Each eval statement is kinda slow. If there are a large enough transactions it can slow the system significantly.

    What kyle was suggesting is spoofing the load in the %INC variable so I only have it complain once and eval once for a given package. Does that help?