On 10 Apr 2006 17:55:24 -0700, Randal L. Schwartz <merlyn@stonehenge.com> wrote:
> >>>>> ""Charles" == "Charles K Clarkson" <[EMAIL PROTECTED]> writes:
>
> "Charles> Dr.Ruud wrote:
> "Charles> : Bryan R Harris schreef:
> "Charles> :
> "Charles> ::   for (1..9) { <>; }
> "Charles> :
> "Charles> :   while (<>)
> "Charles> :   {
> "Charles> :     next if $. < 10;
> "Charles> :     ...
> "Charles> :   }
>
> "Charles>     So a billion line file will require a billion tests
> "Charles> instead of 9. That doesn't seem like a good idea.
>
> If the cost of comparing $. to 10 is significant compared to the
> rest of your loop, you're in the wrong programming language.
>
> However, having said that:
>
> my $meat;
> $meat = sub {
>   $meat = sub { real body of loop here } if $. >= 9;
> };
>
> $meat->() while <>;
>
> There.  Happy?  No more tests.  And now you'll complain about the
> subroutine call. :)

Just to muddy the waters a little more (and hopefully answer a
question I've had for a while): how does the "flip-flop" operator
function here:

    while (<>) {
        next if 1..9;
        # the rest of the code
    }

Is '1..9' just shorthand for '$. <= 9'? Or does the flip-flop become a
no-op once it flips?

(I honestly has had no idea that was going to turn into bad perl
poetry when I wrote it. Sorry.)

Thanks,

--jay


--
--------------------------------------------------
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.dpguru.com  http://www.engatiki.org

values of β will give rise to dom!

Reply via email to