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

[MacPerl] revenge of the for statement



Hi -- my name is Andrew Fiore; i've written to the list in the distant 
past and lurked here for ages. I have a question that might be general 
perl, or it might be a specific MacPerl issue; i don't really know enough 
to know for sure.  Most of the problems I've had in the past have been 
related to line feeds and reading files, so i'm wondering if that's the 
case here. ??

In any case, I'm updating a cgi application that creates HTML files for 
my school's student newspaper. One of my updates from the previous 
version is the ability to read in a configuration file and grab, among 
other things, the names of the writers that the program is to present 
users with when it asks them who wrote an article.  OK, so that sounds 
more complicated than it is.  All I want this part of the code to do is 
read the config file, which looks like this:

------
# Falcon's Cry web conversion script configuration file
# By Andrew Fiore <beany@nando.net>
# version 2.0, November 1997

# Welcome to the Falcon's Cry web converter config file.
# Lines beginning with "#" are comment lines and will not be
# interpreted by the script. Do not uncomment comment lines,
# and do not comment out instruction lines or the script may fail.

# Falcon's Cry root directory, where the script will place files:
fcroot="HD:Server software:WebSTAR:fc:"

# Default writers:
# (Add a writerX line for every writer you'd like to have as
# a predefined choice. Be sure numwriters equals the number
# of people you have listed. WriterX lines above numwriters
# will be ignored, so it's OK if you have extras. However,
# the writerX numbers must begin with one and proceed in order,
# increasing by one each time. You may not have FEWER writers
# than you specify in numwriters. Be careful.
numwriters=5
writer1=Andrew Fiore
writer2=Melanie Hirsch
writer3=Mark Bump
writer4=Spring Blachly
writer5=Lindsey Berutti
writer6=
writer7=
writer8=
writer9=
writer10=
writer11=
writer12=
writer13=
writer14=
writer15=
writer16=
writer17=
writer18=
writer19=
writer20=
------

and come out with an array containing the names of as many writers as the 
user specifies in the config file's "numwriters."  I've tested my code 
that reads the config file into the array @configfile, in which each line 
is an array item. But whenever I run this code below, it outputs an 
endless loop of returns (line feeds, i guess) to the MacPerl window.  
I've tried inserting the line print("@writers");, and the program prints 
nothing there.  Does this mean @writers is empty? I'm quite confused.

Thanks so much for your help!
andrew

---------------

if ("@configfile" =~ /writer1/) {

unless ("@configfile" =~ /numwriters/) {
   die("Config file must include \"numwriters\" information!");
}

$line = 0;
while ($item[0] ne "numwriters") {
   if ($configfile[$line] !~ /^#/) {
      @item = split(/=/,$configfile[$line],2);
   }
   $line++;
}

$numwriters = $item[1];


for ($count=$numwriters ; $count <= 0 ; $count--) {
   $line = 0;
   $comp = "writer$count";
   while ($item[0] ne $comp) {
      print("Key is $item[0], data is $item[1], numwriters is $count.\n");
      if ($configfile[$line] !~ /^#/) {
         @item = split(/=/,$configfile[$line],2);
      }
      $line++;
   }
   $writers[$count] = $item[1];
   }

}

print("FC root directory is $fcroot.\nWriters are: ");
for ($count=1 ; $count == $numwriters ; $count++) {
   print("$writers[$count]\n");
}
-----------



                                 -===-
  "...now you would not think, to look at him, but he was famous long ago
            for playing the electric violin on desolation row..."
                                         - bob dylan

andrew fiore / beany@nando.net / beany@mindspring.com / anandroid@aol.com
                                 -===-


***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch