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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |