Dear monks,

I am moving data from an xml-file into a mysql db and need to make a substitution on the fly to clean up a string so it matches the required "datetime" format (replace a letter with a space and truncate). I naively added the substitution expression to the bind value in the script below and got the following error message:

Can't modify non-lvalue subroutine call at blabla.pl line X
Here is the code I am using:
use strict; use DBI; use XML::XPath use XML::XPath::XMLParser; my $dbh = DBI->connect ("DBI:mysql:database", "root", "password", { RaiseError => 1, PrintError => 0}); my $xp = XML::XPath->new (filename => "input_file.xml"); my $nodelist = $xp->find ('//row'); foreach my $row ($nodelist->get_nodelist ()) { $dbh->do ("INSERT INTO users1 ( create_string, username) VALUES ( +?, ?)", undef, # no need for \%attr $row->find ("CreateDate")->string_value () =~ s/(\d\d\ +d\d-\d\d-\d\d)T(\d\d:\d\d:\d\d).*00/$1 $2/g, $row->find ("UserName")->string_value ()); } $dbh->disconnect ()
Any guidance on where I should go from here would be appreciated.
Regards
---J
Sample data <USERS1> <row> <CreateDate>2008-03-17T13:31:14.345-07:00</CreateDate> <UserName>foo</UserName> <Email>michael@example.com</Email> <UserId>a58d0b09-4f97-42ef-901e-cee41103bc12</UserId> </row> <row> <CreateDate>2008-04-11T14:59:57.123-07:00</CreateDate> <UserName>bar</UserName> <Email>spot@example.com</Email> <UserId>4b618e05-1eca-494b-baa5-ab85bd46f0f3</UserId> </row> </USERS1>

To create table in datatbase
create_table_users1.sql CREATE TABLE users1 ( create_string datetime , username varchar(32) );

In reply to DBI Modifying a bind value by journey

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.