in reply to Re^2: use constant for strings (unary plus)
in thread use constant for strings

I don't want to use the sigil simply because it disables the prototype and thus the constant-ish nature as mentions of the "constant" become regular runtime function calls (otherwise they'd be substituted at compile time). I might as well just use a variable.

Seeing as the unary plus doesn't work here, the next best thing I'd prefer would be (WISCONSIN) - with the parens following it looks quite awkward IMHO.

I like the unary plus in other situations and use it lots though - f.ex

map +(foo($_, "bar"))[3], @baz;
where I would otherwise be forced to use curlies
map { foo($_, "bar"))[3] } @baz;
or another extra pair of parens.
map((foo($_, "bar"))[3], @baz);
I don't like either of the latter two, though I realise quite a few people here will disagree. I think the last one at least is certain not to win any prizes for beauty..

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re^3: use constant for strings (unary plus)
by BrowserUk (Patriarch) on Apr 18, 2003 at 22:06 UTC

    Out of interest, why do you favour map +...., @.. over map{ ... } @..?


    Examine what is said, not who speaks.
    1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
    2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
    3) Any sufficiently advanced technology is indistinguishable from magic.
    Arthur C. Clarke.

      Because the map +expr, syntax is great whe you have exactly one expression - I really dislike having a block around when it is so completely superfluous. The concepts conflict - applying an expression or applying a block. This allows the right idiom to be maintained. Its also concise which is a virtue.

      It also happens to be a bit cheaper since you don't get the overhead of a block.

      What he said.

      Makeshifts last the longest.

        Intriquing. The very best savings I could achieve using map $_, list over map{ $_ } list; was under 1%. And I thought I was the clown of micro-optimisations:)

        The number of chars is identical, and even comparing the dumps using perl -MO:Bblock... show only minimal differences.

        I tend to stick with the block form as it allows me to insert additional statements (like print;) into the block without having to change the syntax which I find especially useful when debugging pipelined maps, grep's and sorts--as used in the ST.

        Personally, I find it visually clearer too. TIMTOWTDI:) YMMV... etc. etc.


        Examine what is said, not who speaks.
        1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
        2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
        3) Any sufficiently advanced technology is indistinguishable from magic.
        Arthur C. Clarke.