in reply to Can anyone make this regex job neater?

I would first split each line on the pipe character and do something with the resulting array.

my @line = split('\|', $_); if ($line[0] eq 'NTE') { # parse NTE line } elsif ($line[0] eq 'OBX') { # parse OBX line } else { # got something unexpected }
I try to avoid using $1, $2, etc. directly.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re^2: Can anyone make this regex job neater?
by Tanktalus (Canon) on Oct 11, 2005 at 16:48 UTC

    Don't forget that if you split it and want to recreate it (as the OP seems to want to do), you should use the "-1" flag to split so as not to lose any blank fields at the end.

    $ perl -e 'print join("::", split q"\|", q"OBX|foo|blah|||"),$/' OBX::foo::blah $ perl -e 'print join("::", split q"\|", q"OBX|foo|blah|||", -1),$/' OBX::foo::blah::::::