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

Re: [FWP] fwp-digest V1 #109 -Reply



Previously I wrote:
> 
> Here's a fun way to generate a table:
> 
>   formline((('@>>'x9)."\n")x9,map{$j=$_;map($j*$_,1..9)}1..9);
> 
> although this is a little shorter:
> 
>   map{$j=$_;map(formline('@>>',$_*$j),1..9);$^A.="\n";}1..9;

Whoops!

In each case above, the table is left in $^A; so, for example:

    formline((('@>>'x9)."\n")x9,map{$j=$_;map($j*$_,1..9)}1..9);
    print $^A;

    map{$j=$_;map(formline('@>>',$_*$j),1..9);$^A.="\n";}1..9;
    print $^A;

And be careful to set $^A='' before each one, if you have more
than one call for formline in a single script.

Anyway, that second way has a heinous usage of map; but it is
easily correctible to this:

    do{$j=$_;formline('@>>',$_*$j)for 1..9;$^A.="\n";}for 1..9;
    print $^A;

And then there's this, which is "in between" the previous two 
methods, and has the advantage of sweet map, as well as single-
statement-ness:

    print
    map{$^A='';$j=$_;formline('@>>'x9,map($_*$j,1..9));$^A."\n";}1..9;


-- 
John Porter


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe