in reply to Re: Datafile doesn't update before being read
in thread Datafile doesn't update before being read

I guess I was trying to keep my program "modular," reduce the number of global variables to a minimum, so I guess that's why didn't just use the array I made earlier later.

In retrospect, however, you're 100% right. I simply made @strmeta a global variable and didn't bother reprocessing the data. Then the problem went away and as an extra bonus, the page loads faster.

Thanks a lot, George!

--ghopper

  • Comment on Re: Re: Datafile doesn't update before being read

Replies are listed 'Best First'.
Re: Re: Re: Datafile doesn't update before being read
by George_Sherston (Vicar) on Jun 06, 2002 at 20:43 UTC
    Your'e welcome. I (and others doubtless) applaud your desire to be modular. How about this, then?: take your subroutine for printing output from an array. Not sure what you're calling this - say print_page. Now, instead of making @strmeta a global, make a local variable and pass a reference to it to the subroutine.

    That is, call your subroutine like
    my @strmeta = ..... [...] print_page(\@strmeta);
    Then in the subroutine make the first line
    my $strmeta = shift;
    And thereafter, where before you had @strmeta use @$strmeta, and where you had $strmeta[$foo] put $strmeta->[$foo] - which will "de-reference" (i.e. get the data out of) your reference $strmeta.

    Then, if you set it up like that, you can call the same subroutine from two different points in your script - (a) when you've created @strmeta from your form input, and (b) when you've created it from retrieved data. Your subroutine won't care where the data comes from, so long as it comes in an array reference.

    For your last trick, put print_page() in a module, and use it in all your other scripts!

    Enjoy!

    § George Sherston