[PBML] Re: Perl: Processing lists
- --- Frank Hale <frankhale@...> wrote:
> Okay I have 2 lists, one which stores URL's andUgh, that is certainly not what you want. If the lists
> another which stores the description of the URL's. I
> want to build up HTML code for these links but if I
> use the following code it loops for a very long time
> creating multiple copies of the same links. How can
> build up the list of links using the 2 lists?
> foreach $desc (@desc)
> foreach $link (@links)
> print "<a ref=\"$link\">$desc</a><br>";
are pre-loaded AND have the exact same number of
elements, then try this:
Deconstruction (this is after all a beginner's list!):
join($str, @list) - this takes a list and produces a
string, using $str as a separator. It's equivalent to:
$list . $str . $list . $str . $list ...
map(expr, @list) - this is my vote for the most
powerful Perl built-in. Once you figure out how map()
can be used, you are well on your way to Perl
wizardry. map() evaluates the expression once for each
item in the @list. Within the expression it sets the
variable $_ to each successive value of @list. The
whole thing is returned as a list.
So for example,
@listb = map($_+1, @lista);
sets @listb to the contents of @lista, but increments
each element by one.
qq!...! is nothing more than another way to write
"...", a quoted string with interpolation, but without
having to 'escape' all the internal double-quote
0..$#link is the list of all the valid subscripts of
Jeff Boes//ICQ=3394914//Yahoo!=jeffboes//AOL IM=jboes
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com