Skip to content

Instantly share code, notes, and snippets.

@matthewpersico
Created March 27, 2022 17:59
Show Gist options
  • Save matthewpersico/aa1bc1990451efc18abae28fb010e2cb to your computer and use it in GitHub Desktop.
Save matthewpersico/aa1bc1990451efc18abae28fb010e2cb to your computer and use it in GitHub Desktop.
#!/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");
#!/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