I have just solved a bug in my code involving a compiled regex.
I am wondering if I have got it wrong or if this is a Perl error.
To explain...

I had a class ABC in which I passed a value to the constructor
(eg: $arg{delim_str} ) and stored this for later use throughout the class:

   $self->{DELIM_RE} = qr/\Q$arg{delim_str}\E/os;

Now when I create 2 class objects, each with a different value of
$arg{delim_str}, the first instance works correctly, but the second
seems to be using the same value that was created in the first instance.

For example:

   my $abc1 = ABC->new( delim_str => q{|} ); 
   # do some stuff with $abc1
   ....

   my $abc2 = ABC->new( delim_str => q{,} );
   # do some stuff with $abc2
   *** does not work because the value of $self->{DELIM_RE}
   *** used in $abc2 is the same as that in $abc1

However if I remove the 'o' option from the regex, everything is OK.

   $self->{DELIM_RE} = qr/\Q$arg{delim_str}\E/s;

I had assumed that even though a regex is compiled once only with the 'o'
option, that instances of class data would be INDEPENDENT of each other.

Any comments welcome...

Maurice 


_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to