G'day tj999,
Reading your entire file into a string and then stepping through that string with a regex could be problematic. Given you know the exact record structure, I'd question whether a regex is even an appropriate tool in this case. Perhaps something as simple as the following would suffice.
#!/usr/bin/env perl use strict; use warnings; my $sep = ',-->'; my $sep_len = length $sep; my $tail = ",\n"; my $last; while (<DATA>) { my ($first, undef, $second) = unpack "A3 A$sep_len A3"; print $last, $sep, $second, $tail if defined $last; $last = $first; } __DATA__ 123,-->456, 456,-->234, 234,-->789, 789,-->123,
Output:
123,-->234, 456,-->789, 234,-->123,
See also:
[I was going to comment on various aspects of your code. I can see haukex has already addressed this; so, rather than repeating it, I'll just say I concur with all the points he's made.]
— Ken
In reply to Re: Multi Line Regex Matches...
by kcott
in thread Multi Line Regex Matches...
by tj999
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |