in reply to Timeout alarm for regex

Take into account that signals behaviour changed in Perl 5.7.3. From then on, signals are deferred and aren't delivered to the program until perl decides it's safe to do so. If you want to get signals immediatly, you'll have to set the environment variable PERL_SIGNALS to the value "unsafe". You can read more about this in perlipc, "Deferred Signals (Safe Signals)".

Update: There's a slow regex in perlre. Try this code with and without the environment variable PERL_SIGNALS:

$SIG{'ALRM'} = sub { die "alrm received"; }; alarm 2; 'aaaaaaaaaaaa' =~ /((a{0,5}){0,5}){0,5}[c]/;

--
David Serrano

Replies are listed 'Best First'.
Re^2: Timeout alarm for regex
by Otogi (Beadle) on Jul 27, 2006 at 17:27 UTC
    The alarm does go of for the example you gave me, however, a regex given by leronim below :
    my $re = ('a*' x80).'(b|c)'; my $str = "a" x 80; $str =~ /$re/;
    Never sets off the alarm. Any idea why that is the case. Thanks.

      Works fine here:

      $ perl $SIG{'ALRM'} = sub { die "alrm received"; }; alarm 2; my $re = ('a*' x80).'(b|c)'; my $str = "a" x 80; $str =~ /$re/; __END__ ... runs forever ... $ PERL_SIGNALS=unsafe perl $SIG{'ALRM'} = sub { die "alrm received"; }; alarm 2; my $re = ('a*' x80).'(b|c)'; my $str = "a" x 80; $str =~ /$re/; __END__ alrm received at - line 1.

      --
      David Serrano

        on windows does not make any change.
        C:\Perl\bin>set PERL_SIGNALS=unsafe C:\Perl\bin>perl -e"$SIG{ALRM} = sub{die}; alarm(1); $re = ('a*' x80). +'(b|c)'; $str = 'a' x 80;$str =~ /$re/;"
        does not finish.

             s;;Just-me-not-h-Ni-m-P-Ni-lm-I-ar-O-Ni;;tr?IerONim-?HAcker ?d;print