my %subs = ( do => sub { return 'c' },
rey => sub { return 'd' },
mi => sub { return 'e' },
fa => sub { return 'f' },
so => sub { return 'g' },
la => sub { return 'a' },
ti => sub { return 'b' }, ) ;
my @notes = qw( do rey mi fa so la ti do rum fmep agog ) ;
{
delete local $subs{ ti } ;
say '=' x 20 ;
for my $note ( @notes ) {
if ( $subs{ $note } ) {
my $sub = $subs{ $note } ;
say join "\t", '', $note, &$sub ;
}
}
}
say '-' x 20 ;
for my $note ( @notes ) {
if ( $subs{ $note } ) {
my $sub = $subs{ $note } ;
say join "\t", '', $note, &$sub ;
}
}
Yeah, I'm still on 5.10. But that made me think.
====================
do c
rey d
mi e
fa f
so g
la a
do c
--------------------
do c
rey d
mi e
fa f
so g
la a
do c
Can you add to a hash only in the local scope?
my %subs = ( do => sub { return 'c' },
rey => sub { return 'd' },
mi => sub { return 'e' },
fa => sub { return 'f' },
so => sub { return 'g' },
la => sub { return 'a' },
ti => sub { return 'b' }, ) ;
my @notes = qw( do rey mi fa so la ti do rum fmep agog ) ;
{
local $subs{ rum } = sub { return 'one' } ;
say '=' x 20 ;
for my $note ( @notes ) {
if ( $subs{ $note } ) {
my $sub = $subs{ $note } ;
say join "\t", '', $note, &$sub ;
}
}
}
say '-' x 20 ;
for my $note ( @notes ) {
if ( $subs{ $note } ) {
my $sub = $subs{ $note } ;
say join "\t", '', $note, &$sub ;
}
}
Yeah, I'm still on 5.10. But that made me think.
====================
do c
rey d
mi e
fa f
so g
la a
ti b
do c
rum one
--------------------
do c
rey d
mi e
fa f
so g
la a
ti b
do c
And you might guess that it's a foregone conclusion that you can modify a hash element locally.
my %subs = ( do => sub { return 'c' },
rey => sub { return 'd' },
mi => sub { return 'e' },
fa => sub { return 'f' },
so => sub { return 'g' },
la => sub { return 'a' },
ti => sub { return 'b' }, ) ;
my @notes = qw( do rey mi fa so la ti do rum fmep agog ) ;
{
#delete local $subs{ ti } ;
#local $subs{ rum } = sub { return 'one' } ;
local $subs{ ti } = sub { return 'FMEP' } ;
say '=' x 20 ;
for my $note ( @notes ) {
if ( $subs{ $note } ) {
my $sub = $subs{ $note } ;
say join "\t", '', $note, &$sub ;
}
}
}
say '-' x 20 ;
for my $note ( @notes ) {
if ( $subs{ $note } ) {
my $sub = $subs{ $note } ;
say join "\t", '', $note, &$sub ;
}
}
The more I play with dispatch tables, the more I imagine practical uses of this. I love cool stuff!
====================
do c
rey d
mi e
fa f
so g
la a
ti FMEP
do c
--------------------
do c
rey d
mi e
fa f
so g
la a
ti b
do c
Installed 5.12 on a server I have access to, and yeah, the 5.12 local mojo works. So cool!
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDelete