in reply to Re: local our $var; What does it do?
in thread local our $var; What does it do?

And with the new refaliasing feature, as I understand it, that becomes:

use v5.22; use feature 'refaliasing'; no warnings 'experimental::refaliasing'; sub sum { \local our @a = shift; my $total = 0; $total += $a[ $_ ] for 0 .. $#a; return $total; }

Replies are listed 'Best First'.
Re^3: local our $var; What does it do?
by ikegami (Patriarch) on Jun 18, 2015 at 17:05 UTC
    our @a; local *a = shift;

    can be safely rewritten as

    \local our @a = shift;

    but you'd normally want

    \my @a = shift;

    since the only reason package variables were used is because lexical variables couldn't be aliased like that.

    That means the code should really become

    sub sum { \my @a = shift; my $total = 0; $total += $a[ $_ ] for 0 .. $#a; return $total; }
Re^3: local our $var; What does it do?
by BrowserUk (Patriarch) on Jun 18, 2015 at 10:49 UTC

    So we loose one line at the point of use; and add 3 at the top of the code. That's progress :)


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
      It's clearly worth it only when used at least four times.
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

        Indeed :)

        But it does beg the question; why when you have to explicitly enable a feature, do you have to also explicitly disable the warnings that are meaningless when you've explicitly requested the feature?

        It's like when I'm using hex constants in a 64-bit build of perl and I have to explicitly disable these asinine warnings:

        Hexadecimal number > 0xffffffff non-portable at C:\test\mandlebrot\dou +bleDouble.pl line 57. Hexadecimal number > 0xffffffff non-portable at C:\test\mandlebrot\dou +bleDouble.pl line 58. Hexadecimal number > 0xffffffff non-portable at C:\test\mandlebrot\dou +bleDouble.pl line 59.

        There is some asinine pedant in p5p adding this shit. I guess I could look up who; but then I'd feel the need to say something personal.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
        In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked