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

I have an array called @carrierLOG. I get the error "attempt to free unreferenced scalar..." when perl executes line 91 below. I don't see anything wrong. Thx!
90: $sv_index = $#carrierLOG + 1 if ($sv_index == 0); 91: $carrierLOG[$sv_index] = "$gs02;$gs04;;$whoami;$chksum;$file +";
Debugger data
91: $carrierLOG[$sv_index] = "$gs02;$gs04;;$whoami;$chksum;$file +"; DB<4> x $carrierLOG[$sv_index] 0 'EMDEON;20101021;;psg0977;58788;LM837P.20101021052601 ' DB<5> s Attempt to free unreferenced scalar: SV 0x400f465c, Perl interpreter: +0x400146f0 at /rims/scripts/chk837.pl line 103. at /rims/scripts/chk837.pl line 103

Replies are listed 'Best First'.
Re: unreferenced scalar
by Ineffectual (Scribe) on Nov 04, 2010 at 18:36 UTC
    I'm not sure you gave us enough code to figure out what's going wrong here. Personally, I use scalar to figure out the number of elements in an array rather than doing $# +1.

    $sv_index = scalar(@carrierLOG) if ($sv_index == 0);

    This may fix your problem because it looks like you may be assigning things into the wrong line of your carrierLOG array and that's causing perl to try to free up memory somewhere. Check that $sv_index is really what want it to be.
Re: unreferenced scalar
by chromatic (Archbishop) on Nov 04, 2010 at 17:24 UTC

    What happens when you use push instead?

Re: unreferenced scalar
by 7stud (Deacon) on Nov 04, 2010 at 19:50 UTC
    my @carrierLOG = (1, "hello", 5); my $sv_index = 0; $sv_index = $#carrierLOG + 1 if ($sv_index == 0); $carrierLOG[$sv_index] = "goodbye"; print "@carrierLOG\n"; --output:-- 1 hello 5 goodbye
Re: unreferenced scalar
by ig (Vicar) on Nov 04, 2010 at 17:45 UTC

    Is the scalar that is being freed the previous value of $carrierLOG[$sv_index]? You could use Devel::Peek to dump it just before the assignment, to see if it is the same one reported in the error. If so, and it's reference count is zero, then the question becomes: how is that element of the array being set?