greets monks,

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:
print OUTFILE `cat $arraymember`;
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:
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


In reply to special context of file names in array? by smallaxe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.