I have a situation where I am unexpectedly getting the Unterminated \g... pattern in regex error message.

In one of my CPAN modules, I have source code in a constructor which tests for the existence of certain directories.

    my @missing_dirs = ();
    for my $dir ( qw| gitdir workdir outputdir | ) {
        push @missing_dirs, $data{$dir}
            unless (-d $data{$dir});
    }
    if (@missing_dirs) {
        croak "Cannot find directory(ies): @missing_dirs";
    }
In the test suite, I have code which composes a path to a non-existent directory and then demonstrates that I get the expected error message when I try to use that path as an argument to the constructor. I use File::Spec->catdir() to compose the path string in an operating system-agnostic way.
    local $@;
    $bad_gitdir = File::Spec->catdir('', qw| home jkeenan gitwork mist-compare |);
    $args{gitdir} = $bad_gitdir;
    $params = process_options(%args);
    eval { $self = Devel::Git::MultiBisect::AllCommits->new($params); };
    like($@, qr/Cannot find directory\(ies\): $bad_gitdir/,
        "Got expected error: missing directory $bad_gitdir"
    );
In all CPANtesters reports to date from Unix-like platorms, this code has worked. There's only one CPANtester submitting reports from Windows (in this case, Strawberry Perl running Perl 5.22.1) and that reporter is showing this test failure:
Unterminated \g... pattern in regex; marked by <-- HERE in m/Cannot find directory\(ies\): \home\jkeenan\g <-- HERE itwork\mist-compare/ at t/002-new.t line 38.
I'm very puzzled by this (and I don't have a Windows box on which to debug this). The test code is clearly using m// as regex pattern delimiters, so I don't understand why, in this environment, \g is somehow being treated as if it were intended to be the end of the pattern.

Thoughts? Work-arounds?

Thank you very much.

Jim Keenan

In reply to Unterminated \g... pattern in regex behaving badly on Windows by jkeenan1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.