in reply to coding style suggestion: (...)[1] vs. [...]->[1]

Some remarks:

$number = (split /\s/, $string)[1];
You probably want /\s+/ to allow for multple spaces.

$number = [ split /\s/, $string ]->[1];

Only a performance reason, because in this case you are also creating an array, but then also creating a reference to it. So you're doing extra work in this case.

But if you're happy with that way, go for it. Just do it that way all the time. Be consistent. Avoid premature optimization!

Liz

Replies are listed 'Best First'.
Re: Re: coding style suggestion
by demerphq (Chancellor) on Sep 19, 2003 at 10:43 UTC

    Be consistent. Avoid premature optimization!

    Agreed totaly. But I personally dont count knowning various idioms relative costs as premature optimization. Premature optimization is when you toil over your code for hours to effect a negligable speed improvement that you havent already justified by some good profiling. Knowning the cost of a particular idiom and avoiding those that are expensive for ones that are inexpensive when the time to write either is equivelent is good practice not premature optimization.

    :-)


    ---
    demerphq

    <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...