in reply to Re^4: Combinations of lists, etc
in thread Combinations of lists to a hash
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
shows that there's a problem with the , metacharacter: I can't figure out how to metaquote it.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
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":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", ], )
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.still active! -------+------------+ | | v v C: 'Prefix\{u\,v\}2={\{w\,x\}}:{b,\{y\,z\}}:{1,2}' ^ ^ ^ ^ | | | | in added curlies --+--------+-+----------+
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Combinations of lists, etc (portability issue)
by LanX (Saint) on Oct 04, 2019 at 22:44 UTC |