Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Regexp::Common and "multidimensional hash lookup disabled" (v5.36+)

by ibm1620 (Hermit)
on Jul 01, 2023 at 22:37 UTC ( [id://11153245]=perlquestion: print w/replies, xml ) Need Help??

ibm1620 has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I need to extract substrings delimited by balanced parentheses, and I installed Regexp::Common to see what it could do. Here is a test program that embeds an example from the doc (https://metacpan.org/pod/Regexp::Common).

#!/usr/bin/env perl use v5.36; use Regexp::Common; while (<>) { /$RE{num}{real}/ and print q{a number}; /$RE{quoted}/ and print q{a ['"`] quoted string}; m[$RE{delimited}{-delim=>'/'}] and print q{a /.../ sequence}; /$RE{balanced}{-parens=>'()'}/ and print q{balanced parentheses}; /$RE{profanity}/ and print q{a #*@%-ing word}; }
Unfortunately, it won't compile:
Multidimensional hash lookup is disabled at /Users/chap/private/perl/r +egcommon line 8, near "'/'}"
It seems that, at some point, it was permissible to write $foo{$bar, $frog}, which was understood by Perl to mean $foo{"$bar$;$frog"}, but this was later disabled (perl 5.33?). And I assume that {-delim=>'/'} is what's triggering the error, with '=>' being a fat comma.

Is Regexp::Common out of date? None of the 28 open issues seems to address this condition. Is there a way to make it work under v5.36 and beyond? Is there a successor to Regexp::Common?

(Incidentally, it seems from searching for "perl multidimensional hash" that most people take this to mean simply chaining keys, a la $thing{$x}{$y}{$z}, which of course is alive and well, as opposed to forming a "composite key" as in $thing{$x, $y, $z}).

Update 1: replaced literals with variables in examples of multidimensional hash lookups, per jwkrahn's comment below.

Replies are listed 'Best First'.
Re: Regexp::Common and "multidimensional hash lookup disabled"
by choroba (Cardinal) on Jul 01, 2023 at 23:50 UTC
    Does
    $RE{balanced}{"-parens$;()"}
    work instead?
    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      Yes, it does. Thanks.
Re: Regexp::Common and "multidimensional hash lookup disabled"
by kcott (Archbishop) on Jul 02, 2023 at 01:31 UTC
      Hi Ken

      > permanent fix would be a bug report providing a patch that adds this statement near the start of Regexp::Common:

      > use if $] >= 5.035, feature => 'multidimensional';

      I doubt that's possible, because the problem happens outside the scope of that module, i.e. when using and calling it.

      I think your "test code" is misleading, because the feature is activated for the remaining lexical scope, not the package alone.

      Can't check till tomorrow tho...

      Cheers Rolf
      (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
      Wikisyntax for the Monastery

      In "Re: Regexp::Common and "multidimensional hash lookup disabled"", I suggested that a patch for Regexp::Common could fix the problem. This was wrong.

      The "source for Regexp::Common" starts with (line 3):

      use 5.10.0;

      This will use the feature bundle :5.10. See "feature: FEATURE BUNDLES" which includes:

      :5.10 bareword_filehandles indirect multidimensional say state switch

      So, the multidimensional feature is already loaded.

      My test included:

      ... package Regexp::Common; use if $] >= 5.035, feature => 'multidimensional'; package main; ...

      which seemed to fix the problem. However, rewriting that as:

      ... package Regexp::Common { use if $] >= 5.035, feature => 'multidimensional'; } package main; ...

      and the problem returns:

      Multidimensional hash lookup is disabled at ...

      I'll be striking the incorrect information from the earlier post. It will be in a spoiler; I won't delete it.

      — Ken

      Thanks, Ken.

      What I couldn't understand was how Regexp::Common's tests were succeeding during installation, and when I invoked them standalone. Finally realized it was because the test scripts didn't have use v5.36; at the top!

      My use of Regexp::Common should be rare enough that I can live with writing use feature 'multidimensional'; when I need to. It sounds like adding it to the module may be tricky. Too bad it'll take a bit of digging for others to discover, although searching for the error now turns up this thread as google's first hit. :-)

Re: Regexp::Common and "multidimensional hash lookup disabled"
by jwkrahn (Abbot) on Jul 02, 2023 at 00:41 UTC
    It seems that, at some point, it was permissible to write $foo{bar, frog}, which was understood by Perl to mean $foo{'bar,frog'},

    $foo{bar, frog} is seen by perl as two barewords separated by a comma, i.e. $foo{'bar', 'frog'}.

    Naked blocks are fun! -- Randal L. Schwartz, Perl hacker
      corrected, thanks.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11153245]
Approved by marto
Front-paged by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2025-07-08 23:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.