I've got a seemingly simple script that is causing me
to tear my hair out and I'm hoping someone can offer
some advice. I'll try to keep it short and sweet.

This script reads in the names of all the files in a
directory given on the command line (the names of
chapters for a book) into a variable called $thename,
then reads an html template named  "abstract.html" and
replaces the string "changeme" in the template with
the name of the chapter, and finally outputs a new
file called  "$thename.html". Everything works dandy
until it's time to replace "changeme" with $thename -
the output file I get has a "." character instead of
the value of the variable. Can anyone see what I've
got wrong? The offending piece is preceeded by the
comment "I have no idea why this doesn't work".

Thanks a lot,
Alex

************************************

#!/usr/bin/perl -w
use strict;

my $current=shift @ARGV;

open READIT,"abstract.html" or die "Cannot open
abstract.html: $!";
opendir DH, $current or die "Cannot open $current:
$!";

#load the contents of abstract.html into an array
my @load=<READIT>;

#initialize $count - it might be nice to know
#how many files we found
my($count);

#run through the directory
foreach my $thename (readdir DH) 
  {
  print "Found $thename\n";
  #create a new file called "thename.html"
  open WRITEIT,">export/$thename.html" or die "Cannot
create file.html: $!";
  #find and replace all of the "changeme"
  #with author name
  foreach(@load)
    {
    #I have no idea why this doesn't work
    s/changeme/$thename/g;
    print WRITEIT;
    }
  close(WRITEIT);
  $count++;
  }
print "Found $count files.\n";
closedir DH;
close(READIT);



        
                
__________________________________
Do you Yahoo!?
Friends.  Fun.  Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/ 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to