for my $id (@selected) { $list{$id}{selected} = 1; } for my $key (keys %list) { print qq(
  • $list{$key}\n"; } #### #!/usr/bin/perl # Script part 1. use warnings; use strict; my $code = << '__CODE__'; %list = ( scalar => 'Plain', ref => 'Overwritten' ); $list{ref}{selected} = 1; for my $key (keys %list) { print "$key: $list{$key}"; print " - Selected" if $list{$key}{selected}; print "\n"; } __CODE__ { no strict; my %list; eval $code; print "Wow: $Overwritten{selected}\n"; } #### # Script part 2. { package StringRef; use overload '""' => sub { shift->{STRING}; }; } { package StringRefHash; use Tie::Hash; our @ISA = 'Tie::StdHash'; sub STORE { my ($self, $key, $value) = @_; $self->{$key} = bless {STRING => $value}, 'StringRef'; } } tie my %list, 'StringRefHash'; eval $code; #### # Script part 3. { my %list; eval "$code;1" or die $@; }