in reply to validate variable-length lines in one regex?

I don’t readily think so ... although, “this being Perl, I’m sure it can be done.”   Most of what would concern me, in addition to the potential complexity, is also the notion of coupling between the various alternatives.   You want to be able to change this thing easily ... to add new “stinkin’ input files” without stinking-up the old ones.   ;-)

One idea that comes to mind is to build-up the process, maybe as a list of (anonymous?) subs, or maybe as very-repetitive subs which call other ones (e.g. “until one of them returns false.”)   Each of those subroutines would match against a particular regex.   (The reason why I didn’t suggest a list of qr// regexes is that you might well need to do “slightly more” in one-or-another of those subroutines . . .)

Replies are listed 'Best First'.
Re^2: validate variable-length lines in one regex?
by uhClem (Scribe) on Jul 06, 2015 at 18:39 UTC

    Yah, this is basically what the StackOverflow fellow suggested, and it looked like something I'd really enjoy doing. Except in this situation, where I may have to do a hundred of these alternate patterns so it'd be a lot easier, albeit uglier, to keep just a list of patterns at the top of the script and toggle the one I want. They're only one line each, while the subs-pile could get huge and unreadable. We're not very concerned with best practices here since this is a one-time torture; no maintainer worries.

    Anyway, it may be as you say, and impractical for other reasons after all, but it's gotten me interested in this basic question of whether the trick is possible at all. If it's true that for variable-length lines a single comparison can catch all fields but not validate, or can validate but not catch all fields, that's an interesting fundamental point.

      I, too, am interested.   I agree, based on this further explanation, that my original suggestion of subs could become unmanageable in the use-case that you describe.   I graciously withdraw my suggestion . . .

      The notion of building a Regex, as BrowserUK originally suggests below and as poj took and ran-with a little later on, is probably the right balance between readability and flexibility.   (All now liberally sprinkled with up-vote pixie-dust...)