#!perl use strict; use warnings; use Config; use Test::More tests => 2; =pod This code provides a test case for a very complex regular expression constructed by Getopt::Euclid v0.2.0. Under some releases of perl (i.e. cygwin 5.10.0 and OS X 5.10.0) the regular expression fails. However, on other systems running the same OS & perl combination, the same code works. A simplified regular expression used in an earlier problem report was discarded. While it apparently duplicated the problem, there was no assurance the simplification did not introduce its own problem. The original Getopt::Euclid generated expression, used below, is trying to do the following: * There is logic there (the exists clause) to prevent matching the string more than once; the --now option is only allowed once according to my Getopt::Euclid directive. * It will match the literal string '--now' followed by an integer (e.g. 0, 10, -42, +1999). If it can, that information is stored in a convoluted hash + array using both the option specification (i.e. '--now ') and the option placeholder (i.e. 'seconds'). * It stores any errors in the @errors array. * All that said, there is still some fine magic I have not taken the time to grok. =cut my %ARGV; my $string = q{It is --now 1234}; my @errors; # If you download the code replace the two character '^N' with a # proper control-N. $string =~ s{ (?: (??{exists$ARGV{q{--now }}?'(?!)':''}) --now [\s\0\1]* (?:([+-]?\d+)(?{($ARGV{q{--now }}||=[{}])->[-1]{q{seconds}} = $^N})) (?:(?}} ||= [{}] }) |(?> (.+)) (?{ push @errors, $^N }) (?!) ) }{thyme}xsm; ok( defined $ARGV{q{--now }}->[-1]{seconds}, 'extraction string defined' ); is( $string, 'It is thyme', 'string replacement worked' ); diag("Perl version = $Config{version} on $Config{osname}:\n"); diag( '$ARGV{q{--now }}->[-1]{seconds} = ' . ( defined $ARGV{q{--now }}->[-1]{seconds} ? "'$ARGV{q{--now }}->[-1]{seconds}'" : 'undef' ) . "\n" ); use Data::Dumper; diag( Data::Dumper->Dump( [ \%ARGV ] ) ); exit 0; #### : 2009-02-16 21:47:21 (C:/Perl510/bin/perl regex_test.pl) 1..2 ok 1 - extraction string defined ok 2 - string replacement worked # Perl version = 5.10.0 on MSWin32: # $ARGV{q{--now }}->[-1]{seconds} = '1234' # $VAR1 = { # '--now ' => [ # { # 'seconds' => '1234' # } # ] # }; #### : 2009-02-16 21:47:21 (perl regex_test.pl) 1..2 not ok 1 - extraction string defined # Failed test 'extraction string defined' # at regex_test.pl line 56. ok 2 - string replacement worked # Perl version = 5.10.0 on cygwin: # $ARGV{q{--now }}->[-1]{seconds} = undef # $VAR1 = { # '--now ' => [ # { # 'seconds' => undef # } # ] # }; # Looks like you failed 1 test of 2.