Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Multiple Line Data from text file to SQL

by clueless newbie (Hermit)
on Mar 03, 2009 at 21:08 UTC ( #747897=note: print w/ replies, xml ) Need Help??

in reply to Multiple Line Data from text file to SQL

# Slurp the file my $Text=do { local $/; <DATA> }; # Assuming that a question begins with a number followed by a period: # Then a question is a question number followed by lines which are not + question numbers. #while ($Text =~ m{(\d+\.\n([^\n\r\f]*[a-zA-Z]+[^\n\r\f]*\n)+)}s) { while ($Text =~ m{((\d+)\.\n(([^\n\r\f]*[a-zA-Z]+[^\n\r\f]*\n)+)(A\)([ +^\n\r\f]*[a-zA-Z]+[^\n\r\f]*\n)+?)(B\)([^\n\r\f]*[a-zA-Z]+[^\n\r\f]*\ +n)+?)(C\)([^\n\r\f]*[a-zA-Z]+[^\n\r\f]*\n)+?)(D\)([^\n\r\f]*[a-zA-Z]+ +[^\n\r\f]*\n)+))}gs) { ### question number :$2 ### question :$3 ### A) :$5 ### B) :$7 ### C) :$9 ### D) :$11 #using g so #$Text=$'; };
works but assumes that a question number of the form \d+\. begins each question, the answers must be A, B, C and D and of the form x) ..., and none of the answers are split so that the trailing portion resembles a question number.

Comment on Re: Multiple Line Data from text file to SQL
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://747897]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2015-12-01 05:18 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (794 votes), past polls