PDA

View Full Version : array reference


vhan
02-24-2004, 12:35 AM
I've got an array of a bunch of html pages. What I'd like to do is to create "Next" and "Previous" links for each of these htmls. Therefore, for the first html in the array, I'd like to be able to grab the second html in the array and put that value into the "Next" href of the first html. For the second html, I'd like to grab the first html in the array for the Previous link, and the third html in the array for the Next link, and so on and so on, until I reach the last html, in which case I'll only need to create a Previous link.

Is this do-able?

Afrow UK
03-05-2004, 06:39 PM
I'm not sure if you are embedding some Perl into an HTMl doc or what, but this would work for a simple Perl script:

my $this_file = "file1.pl"; #change for each file

@htmldocs = ("file1.pl", "file2.pl", "file3.pl", "file4.pl");

foreach (0..3) {
if ($this_file eq $htmldocs[$_]) {
if ($htmldocs[$_ + 1] ne $null) {
print qq~<a href="file~ . $_ + 1 . qq~.pl">Next</a> &gt;~;
}
if ($htmldocs[$_ - 1] ne $null) {
print qq~&lt; <a href="file~ . $_ - 1 . qq~.pl">Previous</a>~;
}
}
}

-Stu