in reply to More problems with CGI::Session

$sid = $cgi=>cookie('hungry') || undef;

Something tells me that => should have been ->.

the CGI=HASH(0xFOO) means the thing you get back is an object from the CGI package (this is your $cgi, and it will probably change if you change the comma arrow to a method arrow).

HTH

Update - erh... I shouldn't be typing :wq in mozilla :)

U28geW91IGNhbiBhbGwgcm90MTMgY
W5kIHBhY2soKS4gQnV0IGRvIHlvdS
ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
geW91IHNlZSBpdD8gIC0tIEp1ZXJk

Replies are listed 'Best First'.
Re: Re: More problems with CGI::Session
by fuzzyping (Chaplain) on Mar 14, 2002 at 23:03 UTC
    That was it! I don't know how you saw that... I though I had good vision. :-P

    Thanks!!!

    -fuzzyping UPDATE: Can anyone answer my 2nd question?

      Unfortunately, I'm not very experienced (read: none) with creating packages or modules, so I've simply "require"-d the necessary sub scripts. If I try to run the main script with full strict-ness, I get all kinds of scope errors from the sub scripts. How can I make these global variables truly global?

      Well... if I'm not mistaken you can make any variable a (package) global variable with the use vars qw($some @vars); pragma. If I'm mistaken, please correct me.

      However, I'd suggest that you take a moment and read a bit about packages and namespaces. You will be able to resolve all those scope issues that use strict; is complaining about by changing from require-ing an external script that contains your subs, to use-ing or require-ing a perl module (*.pm) file. This allows you to manage your variables in nice, neat namespaces . Sure, it's a little more work (and incidentally it took me many readings of the documentation ;) initially but the payoff is huge.

      Good luck fuzzyping!!!!

      ..Guv

        Yeah, I have used  use vars for global cgi stuff in the past. I definitely have to go with your suggestion about .pm's, though - that's such a great way to fly. But there's nothing that says you can't mix it all up - require, use vars, and .pm's! Bugzilla does :-) Man, I love that monstrosity. Sometimes when I'm bored, I like to just read through the crazy things those guys have done.

        Update
        I've thought about this for a couple days... you are not going to use modules, and you will have one main script, some required scripts, and you want to have global variables.

        Well, to make a variable truely global in perl, you just declare it with no 'my': $your_var = "something cool"; If you don't want to get scope warnings, just do $::your_var or $main::your_var. This means that you will be using package variables, not lexical variables (like 'my' or 'our'). Again, for clarity's (and your sanity a few months from now) sake you might want to refer to these with $main:: or $::, since that is the default package you will be using... and as soon as you see these you will know what they are.

        The other option (which might not be as clear a few months after you finish your project) would be to do 'use strict' and then do

        use vars qw {
        (all your global variables here)
        }
        Like I said, I have done this in the past, but I don't think I would do it now.

        Man, I hope this is clear; I'm not good at expressing this kind of thing - unfortunately, I am an intuitive programmer. Let us know how it goes.