Go Back   CodingForums.com > :: Server side development > Perl/ CGI

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-20-2002, 11:46 AM   PM User | #1
sir pannels
Regular Coder

 
Join Date: Jun 2002
Posts: 905
Thanks: 23
Thanked 5 Times in 5 Posts
sir pannels is an unknown quantity at this point
Pulling every .txt file from a dir

hey there,
ok ive been working on quite a big script,
and got to part i cant work out....
the script should pull all the ,txt files form a dir and display them inbeded in html so there is one then next uisng <br> also should be alphabetical but im getting now where...the rest of the code fine..now i just need to finish it with this part of code can someone help me out here?
thanks aload
sir p
sir pannels is offline   Reply With Quote
Old 06-20-2002, 02:47 PM   PM User | #2
chrisvmarle
Regular Coder

 
Join Date: Jun 2002
Location: the Netherlands
Posts: 215
Thanks: 0
Thanked 0 Times in 0 Posts
chrisvmarle is an unknown quantity at this point
I'm working on it

Here's what I got:
Code:
#!/usr/bin/perl

opendir(DIR,".");
@files = sort(grep(/\.php$/,readdir(DIR)));
closedir(DIR);

print "Content-type: text/html\n\n";

$all_data = "";
foreach $file (@files) {
	open(FILE,"$file") || die("Could not find $file. $!");
	@lines = <FILE>;
	close(FILE);
	foreach $line (@lines) {
		$line =~ s/\n/\<br\>/g; # optional
		$line =~ s/\</&lt;/g; # optional
		$all_data .= "$line";
	}
	$all_data .= "<br>";
}

print $all_data;
I hope it's useful to you.

Mzzl, Chris

Last edited by chrisvmarle; 06-20-2002 at 02:51 PM..
chrisvmarle is offline   Reply With Quote
Old 06-21-2002, 12:51 AM   PM User | #3
sir pannels
Regular Coder

 
Join Date: Jun 2002
Posts: 905
Thanks: 23
Thanked 5 Times in 5 Posts
sir pannels is an unknown quantity at this point
hey thanks
gives an error tho/
the logs say file does not exsist ...this is not true or it would be 404...any ideas?
sir pannels is offline   Reply With Quote
Old 06-21-2002, 07:15 AM   PM User | #4
chrisvmarle
Regular Coder

 
Join Date: Jun 2002
Location: the Netherlands
Posts: 215
Thanks: 0
Thanked 0 Times in 0 Posts
chrisvmarle is an unknown quantity at this point
Oops, I tested it with my .php files 'cuz I didn't have any .txt files in my cgi-bin. And I found another little problem. Here is the new code, try this:
Code:
#!/usr/bin/perl

opendir(DIR,".");
@files = sort(grep(/\.txt$/,readdir(DIR)));
closedir(DIR);

print "Content-type: text/html\n\n";

$all_data = "";
foreach $file (@files) {
	open(FILE,"$file") || die("Could not find $file. $!");
	@lines = <FILE>;
	close(FILE);
	foreach $line (@lines) {
		$line =~ s/\</&lt;/g; # optional
		$line =~ s/\n/\<br\>/g; # optional
		$all_data .= "$line";
	}
	$all_data .= "<br>";
}

print $all_data;
Mzzl, Chris
chrisvmarle is offline   Reply With Quote
Old 06-21-2002, 09:04 AM   PM User | #5
sir pannels
Regular Coder

 
Join Date: Jun 2002
Posts: 905
Thanks: 23
Thanked 5 Times in 5 Posts
sir pannels is an unknown quantity at this point
ok cool,
still does the same thing....im thinking it means the dir is missing...i cant see in there where the dir is? it looks like the dir is " . "
sir pannels is offline   Reply With Quote
Old 06-21-2002, 01:26 PM   PM User | #6
chrisvmarle
Regular Coder

 
Join Date: Jun 2002
Location: the Netherlands
Posts: 215
Thanks: 0
Thanked 0 Times in 0 Posts
chrisvmarle is an unknown quantity at this point
opendir(DIR,".");
"." is indeed the directory. It means "current dir", so this script opens the current dir, wich is where your script is running in.

You can change the dot to anything you want. Like "texts" to open a dir named "texts".

Mzzl, Chris
chrisvmarle is offline   Reply With Quote
Old 06-21-2002, 02:55 PM   PM User | #7
sir pannels
Regular Coder

 
Join Date: Jun 2002
Posts: 905
Thanks: 23
Thanked 5 Times in 5 Posts
sir pannels is an unknown quantity at this point
hey Chris,
ok it works with no erros but does not display the info and I have changed it abit..still no errors but if you look at the code then test it yourself look what happens
im stumped...you got any ideas?
or anyone elsE?
cheers
heres the code for this....
Quote:
print "Content-type:text/html\n\n";

parse_form();

$int =$FORM{int};
$band =$FORM{band};

sub parse_form {

print "<html><head><title>TabbersTemple.com - $int tabs for $band </title></head>\n";
print "<body bgcolor=\"#000000\" text=\"#FFFFFF\">\n";
print "<b><small><font face=\"Verdana\">$int Tabs for $band </font><br>\n";

opendir(DIR,"../tabberstemple/tabs/$int/$band");
@files = sort(grep(/\.txt$/,readdir(DIR)));
closedir(DIR);

$all_data = "";
foreach $file (@files) {
open(FILE,"$file") || die("Could not find $file. $!");
@lines = <FILE>;
close(FILE);
foreach $line (@lines) {
$line =~ s/\</&lt;/g; # optional
$line =~ s/\n/\<br\>/g; # optional
$all_data .= "$line";
}
$all_data .= "<br>";
}

print $all_data;
}
thanks
sir p
sir pannels is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:20 AM.


Advertisement
Log in to turn off these ads.