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

I got an odd error in a regex substitution. Here's the code, with the suspicious statement in red, and the error that I got is below.

I've worked around the problem by wrapping the regex in an eval, but this worries me, especially since it is intermittent.

Any ideas?

Thanks, Ian
=============== code ================== sub escape { shift() if ref($_[0]); my $toencode = shift; return undef unless defined($toencode); $toencode=~s/(&#91;^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg +; return $toencode; } =============== error ================ Substitution loop at /&lt;...&gt;/dbc.pm line 248, <> line 60981.

Replies are listed 'Best First'.
Re: perl 5.6.1 bug?
by samtregar (Abbot) on Jun 10, 2004 at 18:04 UTC
    That is one weird regex. It matches something at the start of the string with a single lower-case character, then a single upper-case character, then a number, then an underscore, then any character then a -. So this matches:

       aA0_X-

    But this doesn't:

       aZZ0_X-

    Maybe you should slow down and tell us what you're trying to do here.

    UPDATE: Whoops, never mind. Your node got munged by your attempt to show code without using <code> and hid the square-brackets in the regex.

    -sam

Re: perl 5.6.1 bug?
by Anonymous Monk on Jun 10, 2004 at 19:17 UTC
Re: perl 5.6.1 bug?
by Sandy (Curate) on Jun 10, 2004 at 18:16 UTC
    Can you give an example of what causes it to fail (line 60981 I guess).