Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Segmentation fault

by rks (Initiate)
on Jul 03, 2012 at 14:11 UTC ( #979712=perlquestion: print w/replies, xml ) Need Help??
rks has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I have upgraded the perl version from 5.14 to 5.16. After this update, if I run the script, I am getting 'Segmentation fault'. Is there any way to resolve this.

Any help would be greatly appreciated.

Thanks, rks.

Replies are listed 'Best First'.
Re: Segmentation fault
by tobyink (Abbot) on Jul 03, 2012 at 14:26 UTC

    Segfaults are often caused by your script causing something internal within Perl to go into an infinite loop. Perl's generally smart enough to cope with your script looping infinitely, but can sometimes be tricked into an infinite loop and segfault in its internals.

    An example script that causes a segfault in Perl 5.10 to 5.16 (and perhaps 5.17 as well?)

    use 5.010; use strict; my $a = ['a', 'A']; my $b = ['b', $a, 'B']; push @$a, $b; say "hurrah!" if 'x' ~~ $a;

    The smart match operator is tricked into switching between the two arrayrefs eternally. Each time it follows a reference between the arrays, the stack size grows a little bigger, until bang! Segfault!

    Why your script in particular causes a segfault, we cannot determine without seeing it.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re: Segmentation fault
by daxim (Chaplain) on Jul 03, 2012 at 14:20 UTC
    Start the cpan shell and run the command recompile.

      Exactly.   Remember that every CPAN module includes as part of its implementation a fair amount of C/C++ (so called “XS”) code.   When you change versions of the Perl executable, you will ex minimis need to recompile the versions of what you have.   You probably should upgrade them, too.   There’s a lot of “magic” in the install-scripts, and some of that might be Perl-version aware.   When you have changed the layer of software that’s at the bottom of it all (“Perl itself...”), you need to re-do these things so that everyone’s once again singing from the same songbook.

        Every CPAN module has "C/C++ (so called "XS") code"? Perhaps I don't know what I'm talking about, but aren't there "pure Perl" modules in CPAN that don't have any C/C++/XS code in them? (i.e. only Perl code)

        Actually, after re-reading your wording, maybe I misunderstood you. Are you saying "every module in CPAN" has C/C++ code or are you just talking about the CPAN module itself that has C/C++ code?

      If Perl was installed from platform packages and upgraded this way, it might be best to avoid running cpan against it. Mixing platform packages with installations from cpan can lead to difficulties.

Re: Segmentation fault
by ig (Vicar) on Jul 03, 2012 at 20:05 UTC

    Do you get a segmentation fault with all your scripts? Or is your problem with one particular script? If most work but one fails, it would make sense to investigate that one script in more detail. If most or all scripts are failing, then your installation of perl needs attention. If you provide a bit more information, there are monks who can help you in either case.

      Hi All,

      Thanks for all your replies. It is working after recompiling cpan as per daxim reply. Once again, thanks for your responses.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://979712]
Approved by Corion
and the monastery is silent...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2018-06-25 07:02 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.