Perl Script

Hey! It aint that hard!
Post Reply
bob
BIG GIANT HEAD I Get Free Beer
BIG GIANT HEAD I Get Free Beer
Posts: 7565
Joined: 12/03/01, 12:00 am
Location: St. Louis
Contact:

Post by bob » 06/12/03, 4:40 pm

Anyone got a perl script that takes all the files in a directory and writes them to a single file?

I know sounds easy, but I can't quire get it. Here's what I've got....

<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class=postbody>Code:</font><HR width=100% color=#333333 SIZE=1></TD></TR><TR><TD><FONT class=code><PRE>#!/usr/bin/perl -w


print "Content-type: text/htmlnn";


##############################

$databasefile = "/home/virtual/adeiu/munge.txt";

$dir = "/home/virtual/html/";

opendir(DIR,$dir);
@files = grep -f, grep /.txt$/i, map "$dir/$_", readdir DIR;


foreach $file (@files)
{

open (FILE,$file);



open (DBFILE, ">>$databasefile");

print DBFILE;
close FILE;

}
closedir(DIR);
close DBFILE;</PRE></FONT></TD></TR><TR><TD><HR width=100% color=#333333 SIZE=1></TD></TR></TABLE><!-- BBCode End -->


The problem I'm having is it just pulls a couple of the text files, not all of them..... What am I doing wrong here?


Edited to pull a couple of stupid mistaskes.



_________________
We were talking about the space between us all and the people who hide themselves behind a wall of illusion.....

<font class=editedby>[ This Message was edited by: bob on 2003-06-13 10:46 ]</font>

SOD
BIG GIANT HEAD I Get Free Beer
BIG GIANT HEAD I Get Free Beer
Posts: 5284
Joined: 12/06/01, 12:00 am
Location: here and there

Post by SOD » 06/12/03, 5:01 pm

Tried a discussion group bob? What you wish to do is merge HTML files? There is probly a way. I know merge in other languages can be a tricky process...if you are using linux is there anyway to use bash to implement Merge? But you probly wish to implement this dynamically.
It is better to be here than there - SOD

RedRage
BIG GIANT HEAD I Get Free Beer
BIG GIANT HEAD I Get Free Beer
Posts: 1542
Joined: 12/04/01, 12:00 am

Post by RedRage » 06/14/03, 12:45 pm

duno bout perl but php:

exec("ls -1 > resultfile.txt");

Perl's exec is system() i think but i could be talking out my ass

Post Reply