develooper Front page | perl.perl5.porters | Postings from March 2001

closures and //o (was [Fwd: failure notice])

Thread Next
Rick Delaney
March 30, 2001 21:20
closures and //o (was [Fwd: failure notice])
Message ID:
This is new, isn't it?  Oh, well, here it is again.

-------- Original Message --------
Subject: failure notice
Date: 31 Mar 2001 05:09:26 -0000

Hi. This is the qmail-send program at
I'm afraid I wasn't able to deliver your message to the following addresses.
This is a permanent error; I've given up. Sorry it didn't work out.

This mailinglist does not accept postings crossposted to newsgroups - Contact for help

--- Below this line is a copy of the message.

Return-Path: <>
Received: (qmail 23855 invoked from network); 31 Mar 2001 05:09:25 -0000
Received: from (
  by with SMTP; 31 Mar 2001 05:09:25 -0000
Received: from ([]) by
          (InterMail vM. 201-229-121-120-20010223) with ESMTP
          id <>
          for <>; Fri, 30 Mar 2001 21:07:50 -0800
Sender: rick
Message-ID: <>
Date: Sat, 31 Mar 2001 00:23:07 -0500
From: Rick Delaney <>
X-Mailer: Mozilla 4.72C-CCK-MCD Caldera Systems OpenLinux [en] (X11; U; Linux
2.2.14 i686)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.lang.perl.misc
Subject: Summary: closures and //o (was Re: regex-qr// for search and replace)
References: <>
<> <>
<> <>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

[posted to clpmisc and cc'ed p5p]

This is supposed to be a summary but it's kinda long.

Bart Lateur wrote:
>         sub regexsub {
>             my $re = shift;
>             return sub {
>                 shift =~ /$re/o;
>             }
>         }
>         $sub[0] = regexsub('fo+');
>         $sub[1] = regexsub('ba+r');
>         foreach (qw'foo baaar fooooo bar bbbbbbbbar') {
>            foreach my $i(0, 1) {
>               $sub[$i]->($_) and print "Match for '$_' with regex $i\n";
>            }
>         }
> -->
>         Match for 'foo' with regex 0
>         Match for 'baaar' with regex 1
>         Match for 'fooooo' with regex 0
>         Match for 'bar' with regex 1
>         Match for 'bbbbbbbbar' with regex 1
> In pre-5.6.0, //o and closures don't work too well together. There,
> you'd have to put the closure (the sub that gets returned by regexsub)
> in an eval STRING construct.

I wrote that I get

Match for 'foo' with regex 0
Match for 'foo' with regex 1
Match for 'fooooo' with regex 0
Match for 'fooooo' with regex 1

with my copy of 5.6.0 (and up).

Bart wrote:
> Gee. It works properly in ActivePerl 5.6.0 Build 623 for
> MSWin32-x86-multi-thread,
> Could it be in the patches for multi-thread support?


I recompiled my copy of perl-5.6.0 to include threads and it now 
exhibits the same behaviour as ActivePerl.  I also downloaded and 
compiled ActivePerl without threads and it only gives me the /fo+/ 


It appears that multi-thread support has actually broken /o which is
the only reason it "works".

$ perl -le 'for (qw/foo bar baz/) {print if /$_/o }'
$ perl -v           

This is perl, v5.6.0 built for i686-linux
$ as_perl -le 'for (qw/foo bar baz/) {print if /$_/o }'
$ as_perl -v

This is perl, v5.6.0 built for i686-linux-thread-multi
(with 1 registered patch, see perl -V for more detail) 

When run under -Mre=debug you can see that the regexp is compiled
3 times with threads but only once without.

Maybe this is to be expected?

Also see bug ID 20000810.008 and

Rick Delaney

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About