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

I'm having a problem with CGI::Session. When creating a new object with existing session_id, I sometimes get this error: Can't modify constant item in scalar assignment. At other times, all works fine. I thought the problem was with the timeout, but adding $session->expire('1h') did not solve the problem. It can fail at the first attempt or succeed 20 time and then fail. Any suggestions?
  • Comment on CGI::Session raises inconsistent error 'Can't modify constant item in scalar assignment'

Replies are listed 'Best First'.
Re: CGI::Session raises inconsistent error 'Can't modify constant item in scalar assignment'
by GrandFather (Saint) on May 20, 2007 at 08:44 UTC

    You can get that sort of thing if you apply a substitution to one of the capture variables:

    $1 =~ s/1/2/;

    DWIM is Perl's answer to Gödel
Re: CGI::Session raises inconsistent error 'Can't modify constant item in scalar assignment'
by tinita (Parson) on May 20, 2007 at 11:25 UTC
    as shmem said, you have to post code.
    additionally, you forgot to post the complete error message. normally such an error message shows the file and line where it occurred.
    you wouldn't go to the doctor and say "it hurts" without telling the doctor *where* it hurts, right?
Re: CGI::Session raises inconsistent error 'Can't modify constant item in scalar assignment'
by shmem (Chancellor) on May 20, 2007 at 08:27 UTC
    Without some code there's no way we can tell what's going wrong better than you. See I know what I mean. Why don't you?

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: CGI::Session raises inconsistent error 'Can't modify constant item in scalar assignment'
by clueless newbie (Curate) on May 20, 2007 at 13:26 UTC
    Perhaps you could use caller within a $SIG{__DIE__}/$SIG{__WARN__} handler to trap the error and dump some additional information. Hopefully the call stack will give you enough information to find the error. Otherwise you may need to dump the arguments to each of the routines in the call stack.
Re: CGI::Session raises inconsistent error 'Can't modify constant item in scalar assignment'
by Cody Pendant (Prior) on May 21, 2007 at 01:56 UTC
    In my experience that error occurs when I miss off the dollar sign on a variable.
    $my_variable = 1; # what I meant to type my_variable = 1; # what I actually typed
    So that would explain it. Why the error would happen once in twenty times is still a puzzle though.

    As everyone else has said, show us your code.



    ($_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
    =~y~b-v~a-z~s; print