in reply to local our $var; What does it do?
It's equivalent to:
our $var; local $var;
The first line makes the global $var name visible at the current scope with use strict vars.
The second line localises it in the normal way.
Presumably aimed at simplifying aliasing. As in:
sub sum { our @a local *a = shift; my $total = 0; $total += $a[ $_ ] for 0 .. $#a; return $total; } my @data = getNums(); my $sum = sum( \@data );
Which is nicer than:
sub sum { my $aref = shift; my $total = 0; $total += $aref->[ $_ ] for 0 .. $#{ $aref }; return $total; } my @data = getNums(); my $sum = sum( \@data );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: local our $var; What does it do?
by Anonymous Monk on Jun 18, 2015 at 10:30 UTC | |
by ikegami (Patriarch) on Jun 18, 2015 at 17:05 UTC | |
by BrowserUk (Patriarch) on Jun 18, 2015 at 10:49 UTC | |
by choroba (Cardinal) on Jun 18, 2015 at 12:07 UTC | |
by BrowserUk (Patriarch) on Jun 18, 2015 at 12:38 UTC | |
by ikegami (Patriarch) on Jun 18, 2015 at 17:15 UTC | |
|
Re^2: local our $var; What does it do?
by kcott (Archbishop) on Jun 18, 2015 at 11:31 UTC |