in reply to Reading and Separating Data From a File Using Regex

Another approach using regexes: extract quoted groups:
use warnings; use strict; MAIN: { my $qc = q{"}; # quoting character my $quoted_body = qr{ [^$qc\\]* (?: \\. [^$qc\\]* )* }xms; while (<DATA>) { my (undef, undef, undef, $time, $data1, $data2) = m{ $qc ($quoted_body) $qc }xmsg; print "time: <$time> data1: <$data1> data2: <$data2> \n"; } } __DATA__ example.txt "unimportant1" "unimportant2" "unimportant3" "timeA" "data +1A" "data2A" other.txt "ignore1" "ignore2" "ign\"ore3" "timeB" "data1B" "dat\"a2B" foo.txt "ignore1" "" "ign\"ore3" " timeC " "" "dat\"a2C"
Output:
time: <timeA> data1: <data1A> data2: <data2A> time: <timeB> data1: <data1B> data2: <dat\"a2B> time: < timeC > data1: <> data2: <dat\"a2C>

Replies are listed 'Best First'.
Re^2: Reading and Separating Data From a File Using Regex
by peeeerld (Initiate) on Jan 20, 2009 at 21:21 UTC
    Thanks for the great replys. I am afraid the idea was a bit skewed, though, and instead of example.txt being part of the separation data, I will be reading from example.txt then separating the rest of the data. This is indeed both a learning experience and a problem I came across writing a solution for a task that needs to be done, but I feel like if these could read from a file and split the data they should be golden! Could the revisions be made to suite reading from a file? Thanks so much!

      Perhaps your concept of the Monastery is a "bit skewed." This is not a code-writing machine, nor are the Monks your free-labor pool.

      Please pay respect to their willingness to provide free help (at those times you get stuck after making diligent efforts) by reviewing The Perl Monks Guide to the Monastery and PerlMonks FAQ.

      Then, perhaps you should learn about "read(ing) from a file" and try using your own labor to adapt or adopt the answers you've already been given. A good introductory text (Learning Perl leaps to mind); the Tutorials here; or perhaps even Super Search will give you lots to work with.

      Had you read such nodes as On asking for help and How do I post a question effectively?, you might not be skating so close to multiple downvotes: for the lack of effort displayed (or lack of displayed effort); for posting a question so readily answered with minimal effort; and just BTW for misspelling "suit."

      :-)