in reply to Re^3: Combinations of lists, etc
in thread Combinations of lists to a hash

Are you sure this works with File::Glob 's meta characters sufficiently well?

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Replies are listed 'Best First'.
Re^5: Combinations of lists, etc
by AnomalousMonk (Archbishop) on Oct 04, 2019 at 20:43 UTC

    No. In fact, I hadn't even thought about the general case in which glob metacharacters may be included in the input string, i.e., the string to be permuted (if that's what you're referring to).

    Ferinstance, consider the input string 'Prefix{u,v}2={w,x}:b,{y,z}:1,2'. An attempt to fix this up so that glob produces

    Prefix{u,v}2={w,x}:b:1 Prefix{u,v}2={w,x}:{y,z}:1 Prefix{u,v}2={w,x}:b:2 Prefix{u,v}2={w,x}:{y,z}:2
    shows that there's a problem with the  , metacharacter: I can't figure out how to metaquote it.
    c:\@Work\Perl\monks\NorthernFox>perl -wMstrict -MData::Dump -le "my @proto_globules = ( 'Prefix{u,v}2={w,x}:b,{y,z}:1,2', ); ;; my $rx_comma_in_curlies = qr{ { .*? , .*? } }xms; ;; my $rx_globmeta = qr{ [\[\]{}*?~] }xms; ;; my %globize = ('=' => '={', ':' => '}:{', '' => '}'); ;; for my $globule (@proto_globules) { print qq{A: '$globule'}; $globule =~ s{ ($rx_comma_in_curlies) } { (my $r = $1) =~ s{,}{\\,}xmsg; $r; }xmsge; $globule =~ s{ (?= $rx_globmeta) }{\\}xmsg; print qq{B: '$globule'}; $globule =~ s{ ([=:] | \z) } { print qq{S: '$1'}; $globize{$1}; }xmsge; print qq{C: '$globule'}; my @globs = glob $globule; dd 'DD:', \@globs; print ''; next; } " A: 'Prefix{u,v}2={w,x}:b,{y,z}:1,2' B: 'Prefix\{u\,v\}2=\{w\,x\}:b,\{y\,z\}:1,2' S: '=' S: ':' S: ':' S: '' C: 'Prefix\{u\,v\}2={\{w\,x\}}:{b,\{y\,z\}}:{1,2}' ( "DD:", [ "Prefix{u\\,v}2={w\\:b:1", "Prefix{u\\,v}2={w\\:b:2", "Prefix{u\\,v}2={w\\:{y\\:1", "Prefix{u\\,v}2={w\\:{y\\:2", "Prefix{u\\,v}2={w\\:z}:1", "Prefix{u\\,v}2={w\\:z}:2", "Prefix{u\\,v}2=x}:b:1", "Prefix{u\\,v}2=x}:b:2", "Prefix{u\\,v}2=x}:{y\\:1", "Prefix{u\\,v}2=x}:{y\\:2", "Prefix{u\\,v}2=x}:z}:1", "Prefix{u\\,v}2=x}:z}:2", ], )
    The  \{u\,v\} isn't too bad, but wrapping a pair of  { } permuting curlies around  \{w\,x\} or  b,\{y\,z\} reveals that the comma is still "active":
    still active! -------+------------+ | | v v C: 'Prefix\{u\,v\}2={\{w\,x\}}:{b,\{y\,z\}}:{1,2}' ^ ^ ^ ^ | | | | in added curlies --+--------+-+----------+
    So unless someone can figure out how to metaquote the glob comma-in-curlies operator, it looks like a parser of some kind is the way to go in the general case.


    Give a man a fish:  <%-{-{-{-<

      thanks!

      looks like a windows bug portability issue for me

      DB<54> x glob 'x{\{a\,b\}}y' 0 'x{a\\y' 1 'xb}y' DB<55> p "$^O, $]" MSWin32, 5.024001

      no such effect un linux or termux

      DB<1> x glob 'x{\{a\,b\}}y' 0 'x{a,b}y' DB<2> p "$^O, $]" linux, 5.018002 DB<3>

      > (if that's what you're referring to).

      I was referring to the fact that quotemeta is meant for regexes, which have a differing set of meta-characters.

      update

      from File::Glob#NOTES

      As a concession to user expectation, therefore, backslashes (under GLOB_QUOTE) only quote the glob metacharacters '[', ']', '{', '}', '-', '~' and backslash itself. All other backslashes are passed through unchanged.

      OMG... oO

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice