CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Taking information, matching to a template...

 



modified
Deleted

Jan 22, 2001, 1:53 PM

Post #1 of 7 (998 views)
Taking information, matching to a template... Can't Post

I'm developing a news script for personal use, and I've hit a road bump in one of the admin functions. The script works by taking all the submitted information, putting it into a plain text file database, then matching it to a template and printing it into an html database.

So if I were to make a change to the display template, it wouldn't show up in the HTML database unless the post was after the change. To fix this I started making an Update function. I have no idea why the things I've tried don't work, but it doesnt. I've tried 100s of different methods for doing this but it doesn't work. No matter what it either 1- Takes the most recent post and displays it as many times as there are posts in the database, or 2 - Displays the first post and stops. I'll post the code in the sec, but if you want the rest of the files that go with it, go to http://bctech.arc-network.com/newspost/

Here's the most recent attempt.....

--code--
open (DATA, "database.dat");
&lock(DATA);
@database = <DATA>;
close (DATA);

open (TEMP, "template.html");
&lock(TEMP);
@template = <TEMP>;
close (TEMP);

for ($x = 0; $x < @database; $x++) {
($hline[$x], $date[$x], $num[$x], $usr[$x], $email[$x], $msg[$x], $url[$x], $title[$x], $chop) = split(/``/, $database[$x]);
foreach $line (@template) {
$line =~ s/\[headline\]/$hline[$x]/;
### print "$x - $hline[$x]
";

}
print "@template";
}

###$y = 0;
###foreach $item (@database) {
### foreach $line (@template) {
### $line =~ s/\[headline\]/$hline[$y]/g;
### print "$y - $hline[$y]
";
### print "$line";
### $y++;
###} }

# move this outside of the foreach so you only print
# out the final template once after all the substitution
# is done
#####emplate"

exit;
-- code --

This is driving me crazy.



briggs
Deleted

Jan 23, 2001, 4:12 PM

Post #2 of 7 (982 views)
Re: Taking information, matching to a template... [In reply to] Can't Post

Hi,

I could be wrong, but I think you need to make it <FILEHANDLE> instead of FILEHANDLE:

Code
&lock(<FILEHANDLE>);

Also, using the "pre" tags helps tremendously when posting code.

Ben


modified
Deleted

Jan 23, 2001, 4:27 PM

Post #3 of 7 (979 views)
Re: Taking information, matching to a template... [In reply to] Can't Post

That's not the problem, because &lock(FILE); points to a subroutine in my library.



briggs
Deleted

Jan 23, 2001, 4:31 PM

Post #4 of 7 (977 views)
Re: Taking information, matching to a template... [In reply to] Can't Post

Where do you get the "FILE" though?

Ben


modified
Deleted

Jan 24, 2001, 3:43 AM

Post #5 of 7 (957 views)
Re: Taking information, matching to a template... [In reply to] Can't Post

It's an example. Guys, dont worry about me locking files. It's fine. Thats not the problem.



briggs
Deleted

Jan 24, 2001, 6:52 AM

Post #6 of 7 (955 views)
Re: Taking information, matching to a template... [In reply to] Can't Post

I apologize if I sounded critical, I didn't mean to. I'm just pretty sure that if your passing a filehandle as a parameter to any function, whether it's named "lock" or "print_something", it should be between angle brackets. I could be wrong. I would test it myself, but I'm away from my computer that has Perl installed.

Ben


japhy
Enthusiast

Jan 24, 2001, 6:53 AM

Post #7 of 7 (954 views)
Re: Taking information, matching to a template... [In reply to] Can't Post

Putting a filehandle in <FH> is NOT passing a filehandle. It's calling the readline() function on the filehandle.

To pass a filehandle to a function, you use something like FH, *FH, or \*FH.

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives