smferris has asked for the wisdom of the Perl Monks concerning the following question:


#!/app/perl5.005/bin/perl package First; sub new { bless {}, 'First' }; sub test { my $self=shift; bless $self, 'Second'; } 1; package Second; sub test { my $self=shift; print "Hello World!\n"; } 1; package main; my $t=new First(); print $t,"\n"; # Output: First=HASH(0x2864) $t->test; # no output; print $t,"\n"; # Output: Second=HASH(0xc2864) $t->test; # Output: Hello World!

I have a data(base) load script I am working. It's quite flexible as to the source and the destination of the data. (Could be to<=>from a file, database, etc) Currently I have conditionals to work around problems. EG: Transfering from Sybase 2 Sybase I have a problem with text fields. You can't bind text. Oracle 2 Oracle, longs are implicitly bound (binded?) as a varchar which means any data over 4000 chars and oracle complains, etc. I can work around these issues w/ conditionals but I thought a more elegent approach would be to move this to a module. If the load doesn't work one way, try another approach. (Replace the current namespace w/ a new one and try that.)

This is especially attractive, because the next approach may not even resemble the one that failed. Maybe it fails over to native tools when both backends are the same. Oracle: Exp/Imp.. Sybase: BCP.. Neither of these would require a loop on cursor approach. In fact, it wouldn't require a loop at all! But a select<=>insert cursor loop is "easier" for Sybase to Oracle. (I tried bcp->sql*load. A terrible hack!)

Anyway.. My question is: Is this approach as ellegant as I think? Is it a bad hack and prone to problems? The "original" caller may need to know how the data was actually transfered so replacing the namespace is the only decent way I see to do this. It sounds good to me, being fairly new to PerlOO, and I've always been told, if it looks to good to be true, it probably is.

Your thoughts would be greatly appreciated!

SMF 8)