Gossamer Forum
Home : General : Perl Programming :

Extracting from an array

Quote Reply
Extracting from an array
I would appreciate some help with this: I have a field called <%Pages%> which includes a series of numbers separated by commas (ie. 45,567,13,6). I wish to extract each number so as to use them all in a HTML template. I thus wrote a global with my limited perl experience: my global is named <%pages%>

sub {
my $index = shift;
# get field, split into an array
my ($tags) = GT::Template->tags;
my (@pages) = split /,/, $tags->{Pages};

# just to debug: shows I'm extracting correctly!
my $numberpages = @paras;

# initiate loop to output each element of the array
for ($index=0; $index<@pages; $index++) {
return @pages[$index];
}
# end sub
}

In my HTML, I just want to do a simple loop to show each number:
for page=first to page=last
print page <BR>
next

It's the perl that's not correct. I only have the first number returned. But I very much suspect that there is a far more elegant way of achieving my objective! Thanks for some expert advice!
Subject Author Views Date
Thread Extracting from an array charly 8366 May 2, 2003, 12:14 PM
Thread Re: [charly] Extracting from an array
Paul 8130 May 2, 2003, 12:30 PM
Post Re: [Paul] Extracting from an array
charly 8175 May 2, 2003, 12:49 PM
Thread Re: [Paul] Extracting from an array
charly 8128 May 2, 2003, 1:09 PM
Thread Re: [charly] Extracting from an array
Paul 8134 May 2, 2003, 1:20 PM
Thread Re: [Paul] Extracting from an array
charly 8121 May 2, 2003, 1:38 PM
Thread Re: [charly] Extracting from an array
Paul 8182 May 2, 2003, 2:32 PM
Thread Re: [Paul] Extracting from an array
charly 8120 May 2, 2003, 11:22 PM
Thread Re: [charly] Extracting from an array
charly 8041 Jun 22, 2003, 12:28 AM
Thread Re: [charly] Extracting from an array
Paul 8076 Jun 22, 2003, 1:54 AM
Post Re: [Paul] Extracting from an array
charly 8019 Jun 23, 2003, 9:11 PM
Post Re: [Paul] Extracting from an array
charly 7956 Jul 13, 2003, 6:44 AM