Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

bizarre Carp

by gjh (Initiate)
on Mar 29, 2007 at 12:04 UTC ( [id://607210]=perlquestion: print w/replies, xml ) Need Help??

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

Hi, Okay first of all I'm still a newbie with Perl. I'm having a problem with Carp on ActivePerl 5.8.7/8 and dual core or multiprocessor Win32 (2000/xp/2003) systems. The following is a short reproducer.
use Carp; my_main(@ARGV); sub my_main { my $first = shift @ARGV; carp "Rubbish\n"; exit; }
When executed, it gives:
$ argv 1 Bizarre copy of ARRAY in sassign at C:/progfile/Perl-5.8.8/lib/Carp/He line 45.
The code is written this way for unit testing, the real module starts with the line : main (@ARGV) unless caller();
The reference to @ARGV rather than @_ in 'main' is required for Getopt::Long::GetOptions.
Can I pass @ARGV ?, seems to work on a uniprocessor, Can I fool GetOptions to operate on @_, or can't we test this code :-?
Thanks for any advice

Replies are listed 'Best First'.
Re: bizarre Carp
by xdg (Monsignor) on Mar 29, 2007 at 13:04 UTC

    This looks like a bug, though it seems to be an older one relating to 5.6. That it breaks on a multiprocessor system but works on a uniprocessor makes the likelihood of a bug much higher. Please consider reporting to

    Googling for that error message also revealed one or two comments about people avoiding "shift" in certain circumstances back in 5.6. You might see if that helps.


    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      Please consider reporting to

      I did just that. The bug has been filed as #42166. Interestingly enough, the behaviour changes slightly in blead.

      • another intruder with the mooring in the heart of the Perl

Re: bizarre Carp
by grinder (Bishop) on Mar 29, 2007 at 13:01 UTC

    Can you pass a reference to ARGV and get it to work on that?

    use Carp; my_main(\@ARGV); sub my_main { my $first = shift @{$_[0]}; carp "Rubbish\n"; exit; }

    That gets rid of the error, but I don't know how much of an impact that will have on the rest of your code.

    Otherwise, why don't you just say:

    my_main() unless caller();

    @ARGV is, after all, a global, you don't have to pass it as a parameter. If you want to munge it non-destructively, localise it with local @ARGV = @ARGV.

    • another intruder with the mooring in the heart of the Perl

Re: bizarre Carp
by ikegami (Patriarch) on Mar 29, 2007 at 14:28 UTC
    What about the following?
    sub my_main { my $first = shift(@_); local @ARGV = @_; GetOptions(...); }

    It's even cleaner code (better encapsulation).

Re: bizarre Carp
by runrig (Abbot) on May 09, 2012 at 22:53 UTC
    Bizarre copy of ARRAY in sassign at C:/progfile/Perl-5.8.8/lib/Carp/ line 45.

    This also manifests itself as: "panic: attempt to copy freed scalar"

    Patch for Carp in case anyone is interested. Find the call to format_arg in or Carp/ (depending on version), and replace with (prefix @args with my depending on version also. E.g. in 5.8.8 it's "my @args" in, in 5.14.1 it's just "@args" in

    @args = map { local $@; my $tmp = eval { Carp::format_arg($_) }; defined($tmp) ? $tmp : 'unknown'; } @DB::args;
    And now instead of an unhelpful error message referring to a line in Carp, you'll get the stack trace you wanted, albeit with one or more 'unknown' arguments shown in the function calls.
Re: bizarre Carp
by jrl (Novice) on Nov 29, 2007 at 19:49 UTC
    It looks like this same problem was reported here as #41521 which also claims this is fixed in 5.8.9.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://607210]
Approved by NovMonk
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-05-27 19:53 GMT
Find Nodes?
    Voting Booth?

    No recent polls found