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

[MacPerl] How files are read in (was: for loops)



<snip>
> 3) is it possible that $txt[0] has the entire file, and $txt[1] thru $txt[7]
> are empty?

Yes, that was it exactly, as I finally figured out about an hour after posting
my question.... But I don't understand why.

When I did this:

   open(OBITS,"$filename") || die "Can\'t open file\n";
   @obits = <OBITS>;
   close(OBITS);

      if ($obits =~ /Obituaries<BR>/) {
        $obits = "Obituaries - $LongDate<BR>";
      }
      
      if ($obits =~ /<B>/) {
         push (@names, $obits);
      }
   }

   open(OBITS, ">$filename") || die "Can\'t open file\n";
   foreach $obits (@obits) {
      print OBITS "$obits";
   }
   close(OBITS);

It worked beautifully, making all the proper line for line substitutions. - So
I assume (yes, I'm beginning to learn what happens when one assumes :) that it
read each line of the file into a separate element of the list.
But when I did this:

  open(TXT, "$ObitFile:class.txt") || die "Can\'t open text file for reading\n";
     $txt = <TXT>;
     close (TXT);

  open (TXT, ">$ObitFile:class.txt") || die "Can\'t open text file for writing\n";
     print TXT "<P><FONT SIZE=+1><A HREF=\"$month$day.html\">$TheMonth $day</A></FONT><BR>$NamesList\r";
     for ($i=0; $i<7; $i+=1) {
        print TXT "$txt[$i]";
     }
  close (TXT);

It put the entire contents of the file into the first element of the list. I
know now how to get around it, but I don't understand why.

Also, does anyone have a snippet handy to sort a list of names (i.e. John B.
Doe, Mrs. Mary Smith, Harold Icks) by last name?

Thanks,
Ann
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for G. Ann Campbell
Content-Disposition: attachment; filename="vcard.vcf"

Attachment converted: macnas:vcard.vcf 3 (TEXT/R*ch) (000177DC)