in reply to Re: Sub call isn't returning values
in thread Sub call isn't returning values

As a beginner, I probably do treat programming as alchemy... especially when something isn't working, I try everything I can think of. I certainly want to make sure I do all I can before posting here (and I've learned to wear my asbestos suit!). ;-)

Yes, I forgot to mention... I tried to print out spec_vars and it was empty after the second call to the page (which, of course, explains why variables later on in that second call are empty). However, when viewing the source at the end of the first call, the specs vars on the page have the appropriate data in them. I seem to be losing my data between the first call and the second call.

Lori

  • Comment on Re: Re: Sub call isn't returning values

Replies are listed 'Best First'.
Re: Re: Re: Sub call isn't returning values
by Limbic~Region (Chancellor) on Mar 02, 2004 at 18:31 UTC
    Lori713,
    Have you considered using the following code behind the button push:
    print $CGI->redirect( $CGI->self_url );
    I am not saying this is the most elegant solution, but it should keep the state of things between invocations.

    Cheers - L~R

Re: Sub call isn't returning values
by Abigail-II (Bishop) on Mar 02, 2004 at 21:36 UTC
    As a beginner, I probably do treat programming as alchemy... especially when something isn't working, I try everything I can think of.
    IMO, that's a very wrong thing to do. It won't teach you *anything*. If code works, or if you think it works just because it happens to produce the right output on a few test cases, it's just luck. It won't give you much insight.

    Yes, I forgot to mention... I tried to print out spec_vars and it was empty after the second call to the page (which, of course, explains why variables later on in that second call are empty).
    Well, that's a clear indication that your program isn't getting the data it's expecting. Not setting $|, calling the sub at a different time or cleaning the litter box aren't going to fix that.

    Abigail

      IMO, that's a very wrong thing to do. It won't teach you *anything*. If code works, or if you think it works just because it happens to produce the right output on a few test cases, it's just luck. It won't give you much insight.

      while i generally agree with that, i must say that it sometimes happens to me that i find myself trying out things until i get what i want. of course checking the docs before or after is crucial, but, to tell the truth, i learned a lot of cool perl features by trying out, just for the fun of it. (mostly that happened when playing golf or something, less often when i program production code)
      being curious and creative can help becoming a good programmer, IMHO.