[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] looping while putting things into an array and then usingit...



  I have data stored in a file ($queue_file_path) like this:

a:::b:::c:::d:::e:::f:::g:::h:::i:::j:::k
a:::b:::c:::d:::e:::f:::g:::h:::i:::j:::k
a:::b:::c:::d:::e:::f:::g:::h:::i:::j:::k

Where each of the letters are pieces of data. These can be words, numbers,
or nothing at all. The position where k is is a date and time value. While
data at positions a through j can be the same, the data at position k (the
time) will always be unique an every line.
  I want to search through my data file for a line that has a time value
(the value at position k) that is the same as a time value I provide. I
then want to split that particular line up into the other data points and
use these.
  I must be having problems in the loop area. After this code I show the
output I get.


#assume that the only other choice is to hit one of the queue buttons.
#Have to get the date and time (it's the option value in this case) and 
#use this to pull out of queuedatafile the proper data to rebuild the 
#web page and send it already filled out to the user.
else {
   $thisdateandtime = $option;

   open (QUEUEDATAFILE, "<" . $queue_file_path);
   @queuedatafile = (<QUEUEDATAFILE>);
   $numberlines = (($#queuedatafile + (1 - $[)) + 1);

   #this loop will split the data file up by line numbers. 
   #Then, when @currentline[10] equals $thisdateandtime, break out of the
loop 
   #and use the currentline.
   for ($loop=0; $loop < $numberlines; $loop++) {
      $line[$loop] = <QUEUEDATAFILE>;
      $line[$loop] =~ s/\n$//; #strip off the newline character from the
line.
      @currentline = split ("$sep", $line[$loop]);  #$sep = ":::"
      if (@currentline[10] == $thisdateandtime) {
#         $thelinenumber = $loop;

         #set the variables that correspond to the selected web page. These

         #will go into the fed web page.
         $calltaker = @currentline[0];
         $os = @currentline[1];
         $application = @currentline[2];
         $machinetype = @currentline[3];
         $ldev = @currentline[4];
         $location = @currentline[5];
         $caller = @currentline[6];
         $phonenumber = @currentline[7];
         $problem = @currentline[8];
         $resolution = @currentline[9];
         $dateandtime = @currentline[10];

         last;  #break out of the for loop.
      }
      else {
         print "no match was found for $thisdateandtime", "\n";
         print "time for this line is: @currentline[10]";
      }
   }
   close QUEUEDATAFILE;

   $\="\n";
   print "Content-type: text/html";
   print "Pragma: no-cache", "\n";

   print '<BODY BGCOLOR="#606060" BACKGROUND="GIF/sealBackground.GIF" TEXT
         "#000000" LINK="#FF0000" VLINK="#FF6666" ALINK="#FFAAAA">';
   print '<FORM ACTION="" METHOD="POST"><B>';
   print "<TABLE>";
   print "<TR><TH
ALIGN=right>Date/Time:</TH><TD>&#60;$dateandtime&#62;</TD></
         TR>";
   print "</TABLE>";
   print "calltaker: $calltaker";
   print "os: $os";
   print "application: $application";
   print ":this date and time: $thisdateandtime";

   print '<INPUT TYPE="submit" name="option" VALUE="Submit Trouble
Ticket">';
   print '<INPUT TYPE="reset" name="reset1" VALUE="Clear">';
   print '<INPUT TYPE="submit" name="option" VALUE="Close This Ticket">';
   print "</FORM></BODY></HTML>";

}


Here is the output I get as viewed in a netscape window:

Date/Time:<>

calltaker: os: application: :this date and time: Thu, May 2, 1996 -
02:02:27
am    *Submit Trouble Ticket* *Clear* *Close This Ticket*


  So, you can see that I get throught the loop ok until '@currentline[10]
== $thisdateandtime' (I also used 'eq' in place of '==' with the same
results. I'm not exactly clear on when to use one or the other). 

  I assume that '@currentline[10] == $thisdateandtime' evaluates as true
because I don't go into my else statement.
  However, none of my variables that I try to assign before my 'last'
statement that I use to try to break out of the loop are actually assigned.
This is evident from my output.
  (The reason I get a date to print at all is because of the line 'print
":this date and time: $thisdateandtime";' which uses the original date and
I time I supplied to the function.)

  What's going on? I'm sure it's something basic, but since I'm new to Perl
I just can't see it. If you have any other suggested improvements please
tell me.


thanks,
rob

---------------------------------------------------
This message was created and sent using the Cyberdog Mail System
---------------------------------------------------