Hey guys,

I have been looking for a good example for what I am trying to do, but I am finding it harder than I expected. I have a script that builds an array of words using regex.

What I would like to do is push this array into a MySQL table. The script iterates through a file, line by line, and finds several things per line. e.g.

Each line would be something like this:

Selling a boat for $100. Please call John Smith at 555-1234. My address is 123 Spring Lane, Springfield MO 12345.

So, lets say you have hundreds of lines like this and you want:

@array = (Smith, John, boat, $100, 123 Spring Lane, Springfield, MO, 12345);

I reinitialize the array for each line, so I have an array for the info I want for each "ad". I want to be able to push this into an "ads" table in a MySQL table, but I can't find a good example of specifically doing it with an array.. I got all the way to the VALUES part, and couldn't find a good recipe for the syntax. I was hoping it might be like this:

$query = INSTERT INTO ads ("lname,fname,item,price,street,city,state,z +ip) VALUES (@array);
Thanks for your help in advance.

In reply to DBI and Inserting an Array by carric

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.