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: Beginner:
hashes

 



RobL
Deleted

Apr 21, 2001, 6:19 AM

Post #1 of 2 (198 views)
hashes Can't Post

Hi

OK, this is a really basic question, but I have been trying to figure this out for hours now......

I have two databases as pipedelimited text files. One is a list of links another is a collection of reviews of those links.

I want to write a small script that finds the last 5 reviews and prints them to a page.

However, I am stuck I the following bit of script

#!/usr/bin/perl

#This section opens my links database
open( DB, "c:/database/links.db" );
@links = <DB>;
close(DB);
print "Content-Type: text/html\n\n";

foreach$link(@links) {

($linkid,$linkname,) = split(/\|/,$link);
print "$linkid, $linkname,
";


}


#this section opens by review database
open( DB, "c:/database/review.db" );
@reviews = <DB>;
close(DB);
print "Content-Type: text/html\n\n";

foreach$review(@reviews) {

($review_id,$linkidrev,$name,$email,$rating,$reviewinfo,$date,$ip) = split(/\|/,$review);

print "$review_id,$linkidrev,$name,$email,$rating,$reviewinfo,$date,$ip
";

}

My questions are:

How do I just list the last 5 reviews.

How do I replace the $linkidrev in the review database which is the id number for the link and is $linkid in the links database with $linkname in the print out.

Does that make sense and can anyone help?

Cheers

Rob







Ich
Deleted

Apr 22, 2001, 12:33 AM

Post #2 of 2 (187 views)
Re: hashes [In reply to] Can't Post

Hello,

with
$a_length = scalar(@array_name)
you can get the number of entries in an array.

now you can get the last 5 with the following code

@array_name = ("a","b","c","d","e","f","g","h");

$i=scalar(@array_name) - 1;

$f = $i - 5;


while($i > $f)
{
print $array_name[$i] . "\n";
$i -= 1;
}

bye


perl -e"print((a...Z,' ',A...z)[$_])for(34,$_-41,$i=12,12+$

 
 


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

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