in reply to Re: Regex with lookahead
in thread Regex with lookahead

Yep, Data::Dumper also works, it's just not as "cool".

Here's an alternate that only allows Flatten, in, or out (but note that multiples are allowed)

#!/usr/bin/perl # http://perlmonks.org/?node_id=1196747 use strict; use warnings; use Data::Dumper; while(<DATA>) { /RepeatingGroup\s*=\s* (?<GroupID>\b\w+\b) (\s*,\s* ((?<Flatten>\bFlatten\b)|(?<Direction>\b(in|out)\b)) )* \s*$/x or next; print $_, Dumper \%+; } __DATA__ RepeatingGroup = Waiver, Flatten, out RepeatingGroup = Waiver, out RepeatingGroup = Waiver, out, Flatten RepeatingGroup = Waiver , in RepeatingGroup = Waiver , Flatten RepeatingGroup = LEI, out, Flatten

Replies are listed 'Best First'.
Re^3: Regex with lookahead
by stevieb (Canon) on Aug 05, 2017 at 01:29 UTC

    *cool* is in the eye of the beholder, worthy monk:

    $ corelist Data::Dumper Data for 2017-01-14 Data::Dumper was first released with perl 5.005 $ corelist Data::Dump Data for 2017-01-14 Data::Dump was not in CORE (or so I think)

    To some, "cool" is working without non-core modules, not necessarily what's newer or more fashionable. I'm not saying that Data::Dump is bad, I'm just pointing out that Data::Dumper is available with almost any Perl 5 install.

      IIRC Data::Dump RFC:SHOULD be preferred because it is less exploitable security-wise. I did some searching—the similar names and stemming make it difficult—and could not find a source for my belief though, so take it with a grain of salt. I certainly prefer the default output formatting in any case. :P

        Thanks for this explanation, and your security concern trumps my "if I forget a random use Data::Dumper; print Dumper $x; in a test file, it'll pass on all Perls even though it's not listed as a prereq".

        Not saying that happens often, but it most definitely has happened.