Hi Monkeys,
my input will look something like this:
NTE||L|obr note
OBX|NM|aaA..^Haem^RD2|7.5|g/dL|13.0-18.0|OR|
NTE||L|obx note 1/1 for 3058
OBX|NM|dBf..^TWC^RD2|8.9|10*9/L|4.0-11.0||
And basically, if the line starts with OBX, then I want to take the characters between the second pipe and the ^ and prefix uppercase characters with "U" and lower with "L".
So, aaA becomes LaLaUA (this is for text comparison elsewhere in a lang. that doesn't support case-sensitive string comparison).
This is my main code:
if(m/(^OBX\|)([^\|]*\|){2}([^\^]*)(.*$)/){
my $pre = $1 . $2;
my $read = $3;
my $post = $4;
$read =~ s/[A-Z]/U$&/g;
$read =~ s/[a-z]/L$&/g;
$_ = $pre . $read . $post;
}
I was just curious is there was a more elegant way to do this - preferably a single s///, rather than one match and two substitutions.
Thanks in advance...
Tom Melly, tom@tomandlu.co.uk
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.