smallaxe has asked for the wisdom of the Perl Monks concerning the following question:
i am trying to use an array of filenames, and insert the contents of each pseudo-html file between an html header and footer to make a new static html page.
i was originally hopings i could use something like:but to no avail, so far... then i decided to use the normal file handle approach, by opening the file, iterating through each line in the current file and inserting each line into my new file using a seperate filehandle, and closing each current file each time it loops. the subroutine looks like this:print OUTFILE `cat $arraymember`;
sub catfile { foreach (@dirarray) { $filepage = shift(@dirarray); #print TOCOUT "$filepage\n"; #debug! unless ($filepage eq '') { open (TEMPFILE, $filepage) or die "cannot open $filepage: $!\n"; #print TOCOUT `cat $filepage`; #i wish! while ($newline = <TEMPFILE>) { print TOCOUT "$newline"; #print "$newline"; #debug! } close (TEMPFILE); } } } # end catfile
what i'm getting is each file for output is being written the entire contents of *every* file in the array, instead of just the contents of one file. i think this is because the array i am iterating over doesn't shift like i want it to, but... there is a debug line where i try to print out the filename after each iteration of the array - this works perfectly as expected - one filename per iteration. please excuse the incredibly messy code - it's in the stages of exasperation. question, why is it opening multiple pages? is there an easier way to do this?
thanks extra muchly in advance....edited: Wed Oct 16 16:06:01 2002 by jeffa - code tags s/<br>//g
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: special context of file names in array?
by sauoq (Abbot) on Oct 16, 2002 at 02:17 UTC | |
|
Re: special context of file names in array?
by Enlil (Parson) on Oct 16, 2002 at 01:57 UTC |