in reply to Using list elements within lists contexts with the distributive properties of HTML shortcuts

use map:
print map { a({-href=>$_},$_) } @list;
For the table:
print table(Tr(td[map { a({-href=>$_},$_) } @list]));
will print a single row and:
print table(Tr[map { td[a({-href=>$_},$_)] } @list]);
will print a single column.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)
  • Comment on (jeffa) Re: Using list elements within lists contexts with the distributive properties of HTML shortcuts
  • Select or Download Code

Replies are listed 'Best First'.
Re: (jeffa) Re: Using list elements within lists contexts with the distributive properties of HTML shortcuts
by Anonymous Monk on Jun 09, 2002 at 20:45 UTC

    Thanks. Works perfectly. Any chance I could prevail upon you to explain the use of map instead of passing the ref (\@list) to a()?

    Is it because passing the list ref means that the enumeration of the elements is done out of my scope?

    I can see where I was going wrong with the [], I was using them inside the ()'s instead of as a replacement for them. (back to perlref to try and understand why I should do this, but its always easier to understand working code than see whats wrong with non-working).

    Regards.

      Sure, i will discuss the a() shortcut and let you apply it to the others.

      Each shortcut takes an optional reference to a list and distrubutes it across each element. That you know, but when you try to do this via:

      a( {-href=>$_ }, \@list )
      the default variable is not 'associated' with the list reference. Indeed, the enumeration of the elements is done outside of your scope.

      The only way (that i know of) to 'associate' it is to use a loop instead:

      for (@list) { print a({-href=>$_},$_); } # or print a({-href=>$_},$_) for @list; # or print map {a({-href=>$_},$_) } @list;

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      

        Thanks again. The murk is thinning slowly, just rather more slowly than I would care to admit.