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 XHere is the code I am using:
Any guidance on where I should go from here would be appreciated.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 ()
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>
create_table_users1.sql CREATE TABLE users1 ( create_string datetime , username varchar(32) );
In reply to DBI Modifying a bind value by journey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |