Skip to content

Instantly share code, notes, and snippets.

@happy-barney
Last active August 26, 2020 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save happy-barney/499610c3246bb7a75f5286149d963759 to your computer and use it in GitHub Desktop.
Save happy-barney/499610c3246bb7a75f5286149d963759 to your computer and use it in GitHub Desktop.

Local can be specified many times

{
	local local local local $a;
}

Conditional operator (ternary operator) can be localized effectively providing conditional local

our ($a, $b) = (1, 2);
{
	local (@ARGV ? $a : $b) = ;
	say "$a-$b";
}
{
	($ARGV ? local $a : local $b) = 4;
	say "$a-$b";
}
# Output (without @ARGV):
1-4
1-4
# Output (with ARGV):
4-2
4-2

my vs local consistency

{
	our $a = 1;
	{ $a = local $a = 2; $a++; say $a 
	say $a;
}
# Output:
3
1
{
	our $a = 1;
	{ $a = my $a = 2; $a++; say $a 
	say $a;
}
# Output:
3
2

Nested HEREDOC

say <<"FOO";
STR: ${ \ <<'FOO' };
fofo
FOO
FOO

# Output:
Can't find string terminator "FOO" anywhere before EOF at /home/brano/a.pl line 12.

Interpolated END

say ${
__END__
}
# Outputs:
Global symbol "$__END__" requires explicit package name (did you forget to declare "my $__END__"?) at /home/brano/a.pl line 14.
say ${
\$
__END__
}
# Outputs:
Missing right curly or square bracket at ...
my $__END__ = 'foo';
say ${
\$
__END__
}
# Outputs:
foo
sub __END__ { 'foo' }
say ${
\
__END__
}
# Outputs:
Missing right curly or square bracket at ...
my sub __END__ { 'foo' }
say ${
\
__END__
}
# Outputs:
foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment