Created
March 27, 2022 17:59
-
-
Save matthewpersico/aa1bc1990451efc18abae28fb010e2cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
sub mess_with_dollar_under { | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} in @{[(caller(0))[3]]}, before the loop\n"); | |
for ( qw ( alpha beta gamma ) ) { | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} in @{[(caller(0))[3]]}, in the loop\n"); | |
} | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} in @{[(caller(0))[3]]}, after the loop\n"); | |
} | |
sub direct_assign_to_dollar_under { | |
$_ = 'my switch value'; | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} in @{[(caller(0))[3]]}, before the loop\n"); | |
for ( qw ( alpha beta gamma ) ) { | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} in @{[(caller(0))[3]]}, in the loop\n"); | |
} | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} in @{[(caller(0))[3]]}, after the loop\n"); | |
} | |
my $var = 'foo'; | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]}, \$var is $var in main, before the mess_with_dollar_under() for\n"); | |
foreach ($var) { | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} , \$var is $var in main, in the mess_with_dollar_under() for, before the call\n"); | |
mess_with_dollar_under() and last; | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} , \$var is $var in main, in the mess_with_dollar_under() for, after the call\n"); | |
} | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} , \$var is $var in main, after the mess_with_dollar_under() for\n"); | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]}, \$var is $var in main, before the direct_assign_to_dollar_under() for\n"); | |
foreach ($var) { | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} , \$var is $var in main, in the direct_assign_to_dollar_under() for, before the call\n"); | |
direct_assign_to_dollar_under() and last; | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} , \$var is $var in main, in the direct_assign_to_dollar_under() for, after the call\n"); | |
} | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} , \$var is $var in main, after the direct_assign_to_dollar_under() for\n"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
sub mess_with_dollar_under { | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} in @{[(caller(0))[3]]}, before the loop\n"); | |
for ( qw ( alpha beta gamma ) ) { | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} in @{[(caller(0))[3]]}, in the loop\n"); | |
} | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} in @{[(caller(0))[3]]}, after the loop\n"); | |
} | |
sub direct_assign_to_dollar_under { | |
local $_ = 'my switch value'; | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} in @{[(caller(0))[3]]}, before the loop\n"); | |
for ( qw ( alpha beta gamma ) ) { | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} in @{[(caller(0))[3]]}, in the loop\n"); | |
} | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} in @{[(caller(0))[3]]}, after the loop\n"); | |
} | |
my $var = 'foo'; | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]}, \$var is $var in main, before the mess_with_dollar_under() for\n"); | |
foreach ($var) { | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} , \$var is $var in main, in the mess_with_dollar_under() for, before the call\n"); | |
mess_with_dollar_under() and last; | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} , \$var is $var in main, in the mess_with_dollar_under() for, after the call\n"); | |
} | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} , \$var is $var in main, after the mess_with_dollar_under() for\n"); | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]}, \$var is $var in main, before the direct_assign_to_dollar_under() for\n"); | |
foreach ($var) { | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} , \$var is $var in main, in the direct_assign_to_dollar_under() for, before the call\n"); | |
direct_assign_to_dollar_under() and last; | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} , \$var is $var in main, in the direct_assign_to_dollar_under() for, after the call\n"); | |
} | |
print("dollar under is @{[defined($_) ? $_ : q(undef)]} , \$var is $var in main, after the direct_assign_to_dollar_under() for\n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment