Alternatively, at risk of pimping my own module, Data::Sync is designed to do this sort of operation. Here's an example:

my $h=Data::Sync->new(); $h->source($sourcedbihandle,"select * from source"); $h->target($targetdbihandle,{index=>"MYPRIMKEY", hashattributes=>[field1,field2]}); $h->mappings(field1=>'targetfield1',field2=>'targetfield2'); $h->transforms(targetfield1=>"s/(\w)+\s(\w+)/$2 $1/", targetfield2=>"lowercase"); $h->run;
That would:
read from $sourcedbihandle all records that match the query
Remap the source field names to the target field names
Transform the data in field1 with the regex, and field2 lowercase
Write all records that have changed since the last run.

Deletion isn't supported in v0.06 (on CPAN), but the next version has deletion support; I'm currently trying to up the test coverage, but if you want to /msg me I can send you an early copy.

Update: Just to clarify - writing only records that have changed since the last run is based on hashing a list of attributes. The 'hashattributes' parameter to target() contains a list of the attributes you want to hash.

--------------------------------------------------------------

"If there is such a phenomenon as absolute evil, it consists in treating another human being as a thing."
John Brunner, "The Shockwave Rider".


In reply to Re: Db table to non-alike db table copying by g0n
in thread Db table to non-alike db table copying by Anonymous Monk

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.