Example:

----
#!/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)

In reply to Replacing namespaces by smferris

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.