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

Re: [MacPerl] looping while putting things into an array and thenusing it...



Robert,

In what follows, I raise one procedural question and then attempt to
offer a simpler (and hopefully more efficient means of solving your
problem).  

Note that I haven't tested the pattern match, so you may need to play
with it a bit.

Good luck!

Eric D. Friedman
friedman@uci.edu

[chomp, chomp]

>   for ($loop=0; $loop < $numberlines; $loop++) {

Why not just say $loop < @queuedatafile instead of counting the lines
explicitly? In this context, the array will return the number of
lines, which is what you're aiming for in this iteration, right?

Or better, why not do this:
   open (QUEUEDATAFILE, "<" . $queue_file_path);
while (<QUEUEDATAFILE>) {

# look for your date on the end of each line (stored here in $_)
    if (/^.*$sep$thisdateandtime$/) {
# if you find it, split the line into the various values and exit the loop
        ($call, $os, $appl, $machin, $ldev, $loc,(and so on)) =
                split("$sep", $_);
        last;
    }
}
close QUEUEDATAFILE;

# exit with an error if no matching record was found.

unless (defined($call) {
        die("no matching record found for $thisdateandtime\n");
}

then continue with this:

>   $\="\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
>---------------------------------------------------