
Donna
Deleted
Feb 13, 2000, 4:08 PM
Post #1 of 3
(5394 views)
|
Module Question - Resetting __DATA__
|
Can't Post
|
|
I'm writing (my first) module and have run into a snag. The purpose of the module is to retrieve remote information based on one field of user input. The location of the remote info is held in precompiled data (stored in __DATA__) within the module. Everything works perfectly when I enter one value in the field. I would now like to enter multiple values into the one field (delimited by spaces), toss those split values into an array, and iterate through the array, creating new objects for each value, validating input and retrieving the correct location for the remote data. The problem is that the first value works, but the rest do not. After some troubleshooting, this is happening because the module has already iterated through <DATA> and is not starting at the beginning for the second value. Here's the constructor, etc, within the program: <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> use constant CLASS => "Lookup"; use Lookup; foreach(@value){ #this holds the split field values $news = new Lookup($_); (@errors) = $news->IsValid(); unless(@errors){ (@moreinfo) = $news->DoLookup(); } } </pre><HR></BLOCKQUOTE> Here's the relevant portion of the module: <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> my ($URL,$QUERYDB,$NAME) = ""; while (<DATA> ){ chomp; ($URL,$QUERYDB,$NAME) = split(/\t/,$_); if (lc($NAME) eq lc($self->{_NAME})){ $self->{_URL} = $URL; $self->{_QUERYDB}= $QUERYDB; last; } } </pre><HR></BLOCKQUOTE> In a nutshell, I guess I need to know how to force the module to start at the beginning of __DATA__ for the second and subsequent values. (Though I thought that each new constructor would do that?) Any help would be appreciated. Thanks! [This message has been edited by Donna (edited 02-13-2000).]
|