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: Advanced:
Script for running news articles...

 



edesign
Deleted

Jun 10, 2000, 7:59 PM

Post #1 of 10 (3287 views)
Script for running news articles... Can't Post

Hey there! I am working on a new website, and one of it's main components is the news section. I am trying to get the whole section to run through pearl, so to access an article, you would type in an address such as:
"news.pl?article=06_10_2000_Title_Goes_Here"

The script would then use then open up a text file with the same name (06_10_2000_Title_Goes_Here.txt). SO far, I this all works fine, but here is the problem.

Inside the text file containing the news article, I want it to contain info such as:

Title
Date
Category
Keywords
Descrition
Article (This point Forward)

This way, I can use another script to search throught the text files and more. Although, how can I get the script to know where the actual article begins? Can i say something like "From line 10 on is the article?" Any iideas? Thanks!

-Daniel


monocle
User

Jun 10, 2000, 9:53 PM

Post #2 of 10 (3287 views)
Re: Script for running news articles... [In reply to] Can't Post

I use this all the time:
In the article file put something like <!--BEGIN ARTICLE--> Then as you step through the lines of the article to get the other info, be searching for that exact comment string. Even if it gets served to the browser it will only be an HTML comment.

Hope this helps.

Monocle
Hear great techno music by Monocle at http://www.mp3.com/monocle


edesign
Deleted

Jun 11, 2000, 5:33 AM

Post #3 of 10 (3287 views)
Re: Script for running news articles... [In reply to] Can't Post

Thanks Monocle! So, let's say I have a news file that looks like this:

New Jersey Wins Stanley Cup
June 10, 2000
Sports: Hockey
hockey, new jersey, stanley cup
<!-- Article 001 -->
Last night the New Jersey Devils won the final game in the Stanely Cup playoffs against the Dallas Stars...

How do I let my perl script know that the aticle starts at the line with the <!-- Article 001 -->? Thanks again!

-Daniel


monocle
User

Jun 12, 2000, 9:42 AM

Post #4 of 10 (3287 views)
Re: Script for running news articles... [In reply to] Can't Post

something like this:
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


foreach $fileline(@file){
if ($fileline =~ /<!-- Article (.*) -->/i){
# do something with the article body
# $1 will contain the number of the artice, 001
}
}
</pre><HR></BLOCKQUOTE>

hope this helps

Monocle
Hear great techno music by Monocle at http://www.mp3.com/monocle

[This message has been edited by monocle (edited 06-12-2000).]


edesign
Deleted

Jun 12, 2000, 12:47 PM

Post #5 of 10 (3287 views)
Re: Script for running news articles... [In reply to] Can't Post

Hey monocle,

I used what you told me, and the script successfully locates the <!-- Article (#) --> line, although, from then on, how do I tell it to print everything below it? Thanks!

Here is the code so far:

opendir THEDIR, "$newsdir" &#0124; &#0124; die "Unable to open the news directory.";
@allfiles = readdir THEDIR;
closedir THEDIR;

foreach $file (sort { int($b) <=> int($a) } @allfiles) {
if ("$newsdir/$file" =~ /\.news/) {
open (newsdir, "<$newsdir/$file");

@fileline=<newsdir>;
close(newsdir);
foreach $fileline (@fileline) {
if ($fileline =~ /<!-- Article (.*) -->/i){
print qq~
$fileline
~;
}
}

}
}


monocle
User

Jun 12, 2000, 1:06 PM

Post #6 of 10 (3287 views)
Re: Script for running news articles... [In reply to] Can't Post

There are several ways you could do this. I think this might be the easiest if it works. If you add <!-- End Article --> to the end of the article and use this code:

for $fileline(@fileline) {
if ($fileline =~ m/<!-- Article (.*) -->/ .. $fileline =~ m/<!-- End Article -->/){
print $fileline;
}
}

It should print out each line between the two comments.

Monocle
Hear great techno music by Monocle at http://www.mp3.com/monocle


edesign
Deleted

Jun 12, 2000, 1:19 PM

Post #7 of 10 (3287 views)
Re: Script for running news articles... [In reply to] Can't Post

Hey monocle,

Everything works great now. Thanks so much! Although, one final question... when the script takes my news article and prints it into the news page, it double spaces the article in the HTML code... any idea how to get rid of that? Thanks!

-Daniel


edesign
Deleted

Jun 12, 2000, 1:34 PM

Post #8 of 10 (3287 views)
Re: Script for running news articles... [In reply to] Can't Post

Nevermind. I figured it out... thanks again!

-Daniel


monocle
User

Jun 12, 2000, 1:55 PM

Post #9 of 10 (3287 views)
Re: Script for running news articles... [In reply to] Can't Post

No problem. I'm always willing to help if I have the time and the solution.

Monocle
Hear great techno music by Monocle at http://www.mp3.com/monocle


turkscripts
Deleted

Jun 29, 2000, 2:14 AM

Post #10 of 10 (3287 views)
Re: Script for running news articles... [In reply to] Can't Post

You have to use a separator for individual components. Suppose I select my separator as
<!-- seperator -->

Then your text becomes:

New Jersey Wins Stanley Cup
<!-- seperator -->
June 10, 2000
<!-- seperator -->
Sports: Hockey
<!-- seperator -->
hockey, new jersey, stanley cup
<!-- seperator -->
Last night the New Jersey Devils won the final game in the Stanely Cup playoffs against the Dallas Stars...


Here is the code which splits this text into parts:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


# read the text file to a variable
undef $/;
open(A,"a.txt");
$text = <A>;
close(A);
$/ = "\n";

#split is into parts
($Title, $Date, $Category, $Keywords, $Descrition, $Article) = split("\n<!-- seperator -->
\n", $text);

</pre><HR></BLOCKQUOTE>

This is pretty much it.


------------------
Turk Scripts
http://turkiyem.com/turkscripts/

 
 


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

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