in reply to Reading and Separating Data From a File Using Regex
Output: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"
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 | |
by ww (Archbishop) on Jan 20, 2009 at 22:43 UTC |