in reply to Re: Challenge: Generate a glob patterns from a word list
in thread Challenge: Generate a glob patterns from a word list

OP updated. Don't count the curlies and commas.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^3: Challenge: Generate a glob patterns from a word list (updated x3)
by LanX (Saint) on May 05, 2021 at 19:04 UTC
    furthermore, in your example the elements from the "alphabet" always only appear once

    'a{b,c}d{e,fg{,h,ij}k}l{,m{n,o}}';

    I suppose that is not a given, but this might guaranty a unique solution.

    OTOH if characters can be repeated I'd bet that multiple solutions are possible.

    Please clarify.

    update

    for instance all these glob expressions are equivalent ( I removed the variations where {,a} and {a,} were swapped)

    use v5.12; use warnings; use Data::Dump; use Test::More; test ( [ <{a,aa}> ], [ <{,a}{a}> ], [ <{a}{,a}> ], [ <a{,a}> ], [ <{,a}a> ], ); sub test { my @g = @_; my (%h1,%h2); for my $i (0..$#g) { for my $j ($i+1..$#g) { is_deeply( [sort @{$g[$i]}], [sort @{$g[$j]}], "$i,$j") or ddx $g[$i],$g[$j]; } } } done_testing;

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Re^3: Challenge: Generate a glob patterns from a word list
by LanX (Saint) on May 05, 2021 at 19:28 UTC
    > OP updated. Don't count the curlies and commas.

    you should also add that curlies and commas should be minimal as a second criteria.

    for instance a , {a} and {{a}} are all equivalent.

    best you provide a sub metric

    edit

    sub cmp_glob($g1,$g2) which returns -1, 0 or 1 like cmp does.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      > for instance a , {a} and {{a}} are all equivalent.

      Interestingly, we've found a place where Perl's glob behaves differently to the brace expansion in bash:

      $ perl -wE 'say glob "{{a}}"' a $ echo {{a}} {{a}}

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

        I tend to side with the shell here. Braces which don't enclose a comma are not a glob pattern (for me).


        🦛