If you need to generate these classes dynamically at runtime, then you could use the technique Joost suggested. However, if you have a fixed set of classes which you know at compile time, and are basically just looking to save your wrists from having to type things over and over, then you could use Module::Compile::TT to just expand the code you need at module load time (actually pre compile-time phase).
package A;
# ... code here
use tt ( subclasses => [ map { 'B' . $_ } 1 .. 100 ] );
[% FOREACH subclass IN subclasses %]
package [% subclass %];
our @ISA = qw(A);
[% END %]
no tt;
There is always more than one way to do it ;)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|