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

I am trying to edit a text file for a 'News Flash' application. I am reading in the text file, and parsing it into an array of structs. I can edit the file just fine, but I'm having issues saving the file (or perhaps it's the way that the structs work with arrays.) Here is a code sample where it hangs:

$news[$selectTitle]->title = $query->param('EditTitle');
$news[$selectTitle]->url = $query->param('EditURL');
$news[$selectTitle]->body = $query->param('EditBody');

$selectTitle is the array index of @news accessing the CGI form fields for data. The server doesn't seem to like it.

Replies are listed 'Best First'.
Re: Edit forms use CGI and JavaScript?
by arturo (Vicar) on Apr 09, 2001 at 23:03 UTC

    If you're using an array of *hashes* (which is how I interpreted "structs", you C programmer you =), you need to wrap "title", "url", and "body" in curly braces, so perl knows those are hash keys, not method calls (e.g. $foo->bar looks like $foo is an object of which bar() is a method).

    HTH

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor

      HTH,

      Thanks. I thought about using hashes, but I wasn't comfortable using them with this project. I will consider that advice. As soon as I submited my question, I realized one of my mistakes. The code should have been written without the '=':

      $news[$selectTitle]->title($query->param('EditTitle'));

      I made the same mistake on Friday, and apparently hadn't learned my lesson yet. Thanks for the help. I still may consider the hashes. They seem more straight forward.

      - Mission
      "Heck I don't know how to do it either, but do you think that's going to stop me!"