Dears,

I'm currently trying to load some data coming from a text file into a database.

Here is a sample of data as it can be found in the file

27509. The Sun's declination is: A) the Sun's position relative to the plane of the Equator. B) the distance between the Sun and the horizon. C) the angular distance between the Sun and the celestial North Pole. D) the Sun's position relative to the ecliptic.

The problem is the following:

I would need to be able to handle the question id (the number on the first line), the question and each answer (a,b,c,d). As you can see in the sample above, the data is not very well formatted and sometimes the answer is spread on several lines. The file contains up to 2500 questions ans answers.

So, basically my question is:

How could I parse the file to isolate every question with its answers even if one answer is spread on several lines?

Thanks a million for your help.

P.


In reply to Multiple Line Data from text file to SQL by pie2re

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.