Having got a handle on 'local our', here's an example showing that compared with '\local our'.

#!/usr/bin/env perl use 5.022; use warnings; use feature 'refaliasing'; no warnings 'experimental::refaliasing'; @::data = (1 .. 3); say "Data before pop_sum: @::data"; say "Sum of data: ", pop_sum(\@::data); say "Data after pop_sum: @::data"; say '---'; say "Data before pop_sum_ref: @::data"; say "Sum of data: ", pop_sum_ref(\@::data); say "Data after pop_sum_ref: @::data"; sub pop_sum { local our @data = @{+shift}; my $total = 0; say "\tTotal: $total; Data: @data"; while (1) { $total += pop @data; say "\tTotal: $total; Data: @data"; last if $#data < 0; } return $total; } sub pop_sum_ref { \local our @data = shift; my $total = 0; say "\tTotal: $total; Data: @data"; while (1) { $total += pop @data; say "\tTotal: $total; Data: @data"; last if $#data < 0; } return $total; }

Output:

Data before pop_sum: 1 2 3 Total: 0; Data: 1 2 3 Total: 3; Data: 1 2 Total: 5; Data: 1 Total: 6; Data: Sum of data: 6 Data after pop_sum: 1 2 3 --- Data before pop_sum_ref: 1 2 3 Total: 0; Data: 1 2 3 Total: 3; Data: 1 2 Total: 5; Data: 1 Total: 6; Data: Sum of data: 6 Data after pop_sum_ref:

So, with 'local our', we can do whatever we want with @data and, once local's scope is exited, @::data gets back its previous values. As we'd expect with local.

However, the usefulness of '\local our' in this scenario eludes me. @::data does not get back its previous values. Changing

sub pop_sum_ref { \local our @data = shift;

to

sub pop_sum_ref { \our @data = shift;

produces exactly the same results.

Perhaps it simply not useful in this scenario. Perhaps its not operating as intended.

Update: I've raised a bug report for the \local our issue. I'll update again when I get a ticket number.

Update2: Got the ticket: [perl #125436]

For those wishing to view this, there may be some issues.

I used the perlbug utility, which appeared to run successfully:

Message sent Thank you for taking the time to file a bug report! Please note that mailing lists are moderated, your message may take a while to show up. If you do not receive an automated response acknowledging your message within a few hours (check your SPAM folder and outgoing mail) please consider sending an email directly from your mail client to perlbug@perl.org.

I waited about 10 hours, received no automated response, so followed the above advice and emailed directly.

Thunderbird somehow mangled what was sent: multiple instances of embedding font tags dozens of levels deep. All you'll initially see is:

"Message body is not shown because it is too large."

If you really want to, you can download the text/html content (31.3k) and view it in a browser. However, other than my perl -V output, it mostly contains the same content as you'll find in this thread, so there's little point in doing this unless you really are that interested.

-- Ken


In reply to Re: local our $var; What does it do? (\local our: [perl #125436]) by kcott
in thread local our $var; What does it do? by kcott

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.