You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by bari <ba...@sonicbox.com> on 2000/12/07 18:46:55 UTC

Help needed with MAP expression

Hi there,
Can any one help me what this MAP function does...

 map(/^[\.\d]+$/ ? td({-align=>'right'}, $_) : td($_), @$_)

I am really confused by this one... your help would be appreciated..

						Thank You,

- Bari

RE: Help needed with MAP expression

Posted by jb...@gocho.net.
It takes a reference to an array, and checks to see if each element of the
arry only contains one or more "."s or digits, if it does it calls the td()
function with parameters, returning the result, if not, it returns the element.

I think.

On 07-Dec-2000 bari wrote:
> Hi there,
> Can any one help me what this MAP function does...
> 
>  map(/^[\.\d]+$/ ? td({-align=>'right'}, $_) : td($_), @$_)
> 
> I am really confused by this one... your help would be appreciated..
> 
>                                               Thank You,
> 
> - Bari
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: modperl-unsubscribe@apache.org
> For additional commands, e-mail: modperl-help@apache.org

-- 
Jason Bodnar
jbodnar@gocho.net
Gocho Networks

It could be one of these chemicals here that makes him so smart.  Lisa,
maybe you should try some of this.

                -- Homer Simpson
                   Bart the Genius


[OT] RE: Help needed with MAP expression

Posted by Ed Park <ep...@athenahealth.com>.
The point of this function is to right-align numbers in table-data cells and
keep everything else left-aligned. Note that this is what Excel does by
default (if you type in a number in Excel, it aligns to the right; if you
type in a string, it aligns to the left).

Technically, it should be use in the context of an arrayref that you are
transforming into an HTML table, e.g.:

use CGI qw(:all);
$_ = ['1','abc','2.34'];
print join "", map(/^[\.\d]+$/ ? td({-align=>'right'}, $_) : td($_), @$_);

A useful and clever piece of code, that. But the author probably should have
commented it. :)

cheers,
Ed


-----Original Message-----
From: bari [mailto:bari@sonicbox.com]
Sent: Thursday, December 07, 2000 12:47 PM
To: modperl@apache.org
Subject: Help needed with MAP expression


Hi there,
Can any one help me what this MAP function does...

 map(/^[\.\d]+$/ ? td({-align=>'right'}, $_) : td($_), @$_)

I am really confused by this one... your help would be appreciated..

						Thank You,

- Bari

---------------------------------------------------------------------
To unsubscribe, e-mail: modperl-unsubscribe@apache.org
For additional commands, e-mail: modperl-help@apache.org


Re: Help needed with MAP expression

Posted by Matt Sergeant <ma...@sergeant.org>.
On Thu, 7 Dec 2000, bari wrote:

> Hi there,
> Can any one help me what this MAP function does...
>
>  map(/^[\.\d]+$/ ? td({-align=>'right'}, $_) : td($_), @$_)

$_ contains an array ref. It loops through each entry in the array ref. If
the entry is a number (by the above regexp's naive view of numbers), it
maps it to <td align="right">number</td>, otherwise it maps it to
<td>value</td>.

The use of $_ as the container for the array ref, while using map (which
gives you a $_ inside the map expression) is scary scary obfuscated
nastiness and deserves a slap for whoever wrote it.

-- 
<Matt/>

    /||    ** Director and CTO **
   //||    **  AxKit.com Ltd   **  ** XML Application Serving **
  // ||    ** http://axkit.org **  ** XSLT, XPathScript, XSP  **
 // \\| // **     Personal Web Site: http://sergeant.org/     **
     \\//
     //\\
    //  \\