Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^5: Combinations of lists, etc

by AnomalousMonk (Archbishop)
on Oct 04, 2019 at 20:43 UTC ( [id://11107068]=note: print w/replies, xml ) Need Help??


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

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:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^6: Combinations of lists, etc (portability issue)
by LanX (Saint) on Oct 04, 2019 at 22:44 UTC
    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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11107068]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-23 20:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found