in reply to References, Prototypes, and read-only values

Well, after reading Tom Christiansen's thoughtful rant on prototypes, I'm inclined to agree with him. I fixed this problem, but the experience is worth telling. The real problem was not in the original code, but in a line in the GetSSNameFromFile subroutine. Near the end was the following line of code:
GetSSNameFromFile( $s_ParentFileName, $$rs_OutputFile, $$rs_RecurseLabel );
You see, this is a recursive function. The scalar $$rs_RecurseLabel is essentially a count of our current recurse depth. That explains why I'm incrementing it when I first enter into the function. But, the real problem I believe was caused by this call. I don't know exactly why, however. I simply switched from the implicit reference creation by the prototype to not using prototypes. I handle the references myself using hard references. This seems to fix the problem. One nicity of this approach is that the above code now becomes:
GetSSNameFromFile( $s_ParentFileName, $rs_OutputFile, $rs_RecurseLabel );
I just pass the hard reference.

Thanks for the replies,

Dave

Replies are listed 'Best First'.
Re: Re: References, Prototypes, and read-only values
by bbfu (Curate) on Feb 28, 2001 at 02:58 UTC

    I believe the reason that the recursive call causes the error is that when you're inside the function, the function is not defined yet. Thus, the recursive call does not see the prototype and thus does not automatically pass the parameter by reference. (See also ichimunki's reply.)

    You could probably fix that and keep the prototype (if you wanted, though it's probably best to ditch the prototype anyway) by changing your recursive call from:

    GetSSNameFromFile ( $s_ParentFileName, $$rs_OutputFile, $$rs_RecurseLabel );
    To:
    GetSSNameFromFile ( $s_ParentFileName, $$rs_OutputFile, $rs_RecurseLabel );

    Don't quote me on that, though. I'm not 100% sure that would work (I didn't test it).

    bbfu
    Seasons don't fear The Reaper.
    Nor do the wind, the sun, and the rain.
    We can be like they are.