in reply to Re: Using $_ as a temp var, especially in functions
in thread Using $_ as a temp var, especially in functions

The biggest argument against it that I can see is that the for will probably be translated to a given in Perl 6, while your local probably wouldn't.
  • Comment on Re: Re: Using $_ as a temp var, especially in functions

Replies are listed 'Best First'.
Re: Re: Re: Using $_ as a temp var, especially in functions
by BrowserUk (Patriarch) on Oct 24, 2002 at 00:08 UTC

    Interesting point. I hadn't considered Perl 6, I'm trying hard not to get excited about until it's a little closer to fruition.

    When you say "the for will probably be translated to a given", do you mean by an automated process? Is there an intention to provide a p5top5.pl or binary? I thought that the route was to have a p5 'mode' rather than conversion?

    Given all the different ways the scalar value in the for loop could be provided

    for ($scalar) {...} for (funcReturningScalar()) {..} for ($hash{of}{some}{arbitrar}{size}{returning}{scalar}) {...} for($$hash{returning}{refToScalar}) { ... } # Many more

    Unless this p5top6 processor is going to act at the bytecode level, its going to have to be a fairly sophisticated piece of code to catch all the possible variations where the topicaliser of the for returns a scalar and not a list? Would it be that much more work to have it check to see if the first line inside a bareblock was local $_ = expression; which by definition must be assigning a scalar?

    Thinking about this further, I'm not sure I understand though. As given is a case-type construct, converting a one-time for to a given would result in some strange code

    for ($scalar) { # do stuff; }

    Becoming

    given ($scalar) { when <<always>> { # do stuff; } }

    I'm not quite clear how you would express the always? Though I assume given will have an equivalent of C's default: clause, so I guess it could become

    given ($scalar) { default { # do stuff; } }

    But I'm not sure that's much better.


    Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!