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

is there anything obvious about this code which would cause a segmentation fault?

my $style_file = $$config{'dir'}."/"; $style_file .= 'main/'.$$config{'style'}.".xsl";

$$conf{'dir'} and $conf{'style'} are initialized and concatenated without a problem; the error occurs when I add remove the '/' after 'main'

Hoping for a fresh set of eyes. Thanks...

Replies are listed 'Best First'.
Re: Segmentation fault on concat
by dave_the_m (Monsignor) on Nov 18, 2004 at 01:06 UTC
    Perl should never segfault(*). If you can reduce it to a small standalone program that exhibits the segfault, and if it still segfaults using 5.8.5, then report it using perlbug.

    Dave.

    (*) ignoring of course: deeply recursive regexes, foreach loops that modify the loop array, functions that delete variables used by the caller in the arglist, anything involving /(?{...})/, and of course anything with the slightest whiff of XS.

      "Perl should never segfault(*). "

      Why ;-?

      It might make sense to say that it is not really up to the OP to cause seg fault, unless he is directly doing some c code through Perl. But Perl seg faults, as what inside is c, and c seg faults.

      Does't matter whether his code is bad or good. If Perl seg faults when run his code, it is still a bug in Perl.

      Update:

      After read gaal's reply, and also some private chat with her, I think that I might have misunderstood dave_the_m's intention, and actually he meant the same thing as what I put in my reply.

        I believe dave_the_m meant that perl isn't supposed to segfault, and that if it does it's a bug in perl -- not to claim the OP was lying :)
      anything involving /(?{...})/

      Care to elaborate on that? I don't know what problem you're referring to.



      ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
      =~y~b-v~a-z~s; print
        Care to elaborate on that? I don't know what problem you're referring to
        I can't remember the exact details off the top of my head, but I seem to remember that trying to clone an anon sub within an re_eval is bad news. I'm currently in the process of rewriting the (?{...}) implementation for 5.10.0 to avoid such problems.

        Dave.

Re: Segmentation fault on concat
by graff (Chancellor) on Nov 18, 2004 at 01:44 UTC
    I'm all for dave_the_m's advice to try demonstrating the bad behavior in a minimal script. This often leads to finding a bug that you weren't looking for previously.

    But apart from that, I'm wondering why you wouldn't do your string assignment some other (possibly simpler) way, such as:

    my $style_file = sprintf "%s/main/%s.xsl", $$config{dir}, $$config{sty +le};
    or maybe:
    my $style_file = join "/", $$config{dir}, 'main', "$$config{style}.xsl +";