Think about Loose Coupling | |
PerlMonks |
Re: Regular expressionby ELISHEVA (Prior) |
on Feb 09, 2009 at 13:00 UTC ( [id://742413]=note: print w/replies, xml ) | Need Help?? |
But being a 'newbee' to perl I cant find a redundant way to do get the first line parsed. Could any one give me some suggestions/directions how to get them parsed. Am I right in guessing your problem is that "one line is not like the others?" (well, actually 2). I note that your input has three types of lines each with a distinct beginning, matching the following regexes:
You can use these distinctions to choose which function should parse each line:
In your parse_experiment(...) subroutine you would put further regexes to break up the experiment line and extract the data you need. To get the data you want you will need to call split(...) once with a regex describing the delimiter between the fields in your experiment record. Then for the particular field containing "rs...", call it again with '-' as the delimiter:
Note 1: Since you say you are new to Perl I've put in extra comments. In your production code you should probably leave them out Note 2: Although this looks like code, it is really meant as pseudo code. This code uses <DATA> as the input stream (that's the stuff below the __DATA__ token), but of course you will want to replace it with your real stream. Also, I have no idea of what you need to do with the parse results so I haven't defined those subroutines. Most likely you will need to pass additional data to the your parsing subroutines or capture return values. Note 3: This code makes an unrealistic assumption that your data has no junk in it. Most data does, so you would also need to supplement it with a lot of error checking code and possibly more elaborate regexes to handle wierd field delimiters, missing fields, and the like. But hopefully it will give you a general idea of how tobreak down the problem to suit your particular situation. Best, beth
In Section
Seekers of Perl Wisdom
|
|