This smells a lot like homework, so I'm not posting a full answer -- hints only!

Heh - well, not really, since I already have a solution.

It was just that I was curious to see if such a task could be handled with a single regex, or whether my instinct to break the job into seperate regexes was correct.

Thanks to all for input - it looks like my original instinct was correct. Other solutions exist (of course - hey, it's perl), but split is inconvenient, since I'd need to rejoin later. Maybe it would be a little faster - I dunno - but (high) speed isn't really an issue with this particular job.

Once again, thanks to all, and if someone does come up a single regex, I'd still be curious to see it.

Here, btw, is the full code I'm using - if anyone notices anything dangerous or just plain silly, feel free to comment. Always happy to learn.

use strict; open(IN, $ARGV[0])||die "Cannot open $ARGV[0] for read:$!\n"; my @lines = <IN>; close IN||die "Cannot close $ARGV[0]:$!\n"; open(OUT, ">$ARGV[0]")||die "Cannot open $ARGV[0] for write:$!\n"; foreach(@lines){ 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; } print OUT||die "Cannot write to $ARGV[0]:$!\n"; } close OUT||die "Cannot close $ARGV[0]:$!\n";
Tom Melly, tom@tomandlu.co.uk

In reply to Re^2: Can anyone make this regex job neater? by Melly
in thread Can anyone make this regex job neater? by Melly

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.