[Date Index][Thread Index]
[Date Prev][Date Next][Thread Prev][Thread Next]

Re: Creating a new tag



Why don't you use perl's split? I think it should work easily in a way
similar to this:

<:{my @s;
@s = split("\n","%body");
print "<table>\n";
foreach (@s) {
    print "<tr><td>" . join("</td><td>", split(",",$_)) . "</td></tr>\n";
}
print "</table>\n";
}:>

Of course, to make it embeddeble in perl (which I never happened to
have to use until now), you will have to use the <perl:...>-tags that
you will find in the wml_macros man page (or via wmd).


On Sat, Jul 15, 2000 at 01:09:19AM +1000, Malcolm Edwards wrote:
> Hi,
> 
> I've been moving my web site to WML, and I'm writing a function to
> convert csv to tables, like this:
> 
> <TABLE>
> <CSVTABLE>
> a,b,c
> d,e,f
> g,h,j
> </CSVTABLE>
> </TABLE>
> 
> which becomes:
> 
> <TABLE>
> <TR><TD>a</TD><TD>b</TD><TD>c</TD></TR>
> <TR><TD>d</TD><TD>e</TD><TD>f</TD></TR>
> <TR><TD>g</TD><TD>h</TD><TD>j</TD></TR>
> </TABLE>
> 
> 
> The function I've written so far is:
> 
> <define-tag csvtable endtag=required>
> <perl>
>     <perl:assign>%body</perl:assign>
>     $perl_var0 =~ s/^\n//ismg;
>     $perl_var0 =~ s/^/\<TR\>\<TD\>/ismg;
>     $perl_var0 =~ s/,/\<\/TD\>\<TD\>/ismg;
>     $perl_var0 =~ s/$/\<\/TD\>\<\/TR\>/ismg;
>     print $perl_var0;
> </perl>
> </define-tag>
> 
> Which is very similar to the way I used to do it in perl (I realise I
> should probably get $perl_var0 some other way).
> 
> However, this results in:
> 
> <TABLE>
> <TR><TD></TD></TR>
> a,b,c
> d,e,f
> g,h,j
> </TABLE>
> 
> It appears that ePerl is ignoring the /m switch as getting $perl_var0 by
> itself works. Is something working differently to normal perl, or is
> something else wrong?
> 
> BTW, where are all the <perl:...> tags documented? I found <perl:assign>
> in the wml library, but I've no idea what all the others do.
> 
> Regards,
> 
> Malcolm Edwards
> ______________________________________________________________________
> Website META Language (WML)                www.engelschall.com/sw/wml/
> Official Support Mailing List                   sw-wml@engelschall.com
> Automated List Manager                       majordomo@engelschall.com
> 

-- 

--------------------------------------------------------------------------
Albert Reiner                                   <areiner@tph.tuwien.ac.at>
Deutsch       *       English       *       Esperanto       *       Latine
--------------------------------------------------------------------------
______________________________________________________________________
Website META Language (WML)                www.engelschall.com/sw/wml/
Official Support Mailing List                   sw-wml@engelschall.com
Automated List Manager                       majordomo@engelschall.com