Bob, et al -- ...and then Bob Showalter said... % % David T-G wrote: % > % > suddenly occurred to me that I could probably change my % > record separator % > from \n to \n\n (a blank line) and grab the whole record that way. % % Yes, or set $/ = '' to get "paragraph" mode. That's a little more flexible,
Ah, yes; that's what I meant. % as Perl will treat any sequence of multiple blank lines as a record % separator. Right. That's a Good Thing(tm). % % > Assuming I figure out how to do that, then how do I match the pieces? % > % > The file looks a lot like % > % > header stuff % > code unit % > owner home_phone work_phone % > addr city, st zip % > % > where any of the phone numbers or the addresses might be % > missing, but we % > can count on the column positions for formatting (and thus parsing). ... % % If the paragraphs have a definite fixed format, usually unpack() is the % easiest way to grab the data. Use 'x' in your pattern to skip over bytes, % and 'A' to extract a sequence of bytes. So, if you want to skip 20 chars, % then grab 8 chars, then skip 32 chars, then grab 15 chars, you use: % % my @fields = unpack('x20 A8 x32 A15', $record); % % (use lowercase 'a' instead of 'A' if you want to preserve trailing blanks on % the fields you extract.) Well, they do but the lines might be short. That is, we have unitcode 101 Short Way Owner Address ... unitcode 206 Longer Circle Owner vonLongName, III Address as well as phone numbers that might or might not be there. I'm not sure how I'd unpack anything beyond the first possibly-in-a-different-column newline. I suppose I should have said "we can count on the starting column positions if we get that far out in a given record", which is probably different! % % Otherwise, you can construct regexes that grab what you're looking for. % Depending on your regex, you might need to use the /s and/or /m modifiers to % change the way ^, $, and . match within the multi-line string. I suppose this will be the way to go, then. I don't see how /s and /m will change the begin- and end-of-line matching, though... Where do I look for that? Thanks again & HAND :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, "Science and Health" http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg!
pgp00000.pgp
Description: PGP signature