Leser: 2
3 Einträge, 1 Seite |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; use Tk; local $Data::Dumper::Indent = 0; my $mw = MainWindow->new(-title => "Tk / Eval"); my $expr = ''; my $input = $mw->Entry(-width => 50, -textvariable => \$expr); my $output = $mw->Listbox(-width => 50, -height => 15); my $data = { mw => $mw, input => $input, output => $output, expr => \$expr, }; $input->bind('<Return>', [\&evalCode, $data]); MainLoop(); sub evalCode { my (undef, $data) = @_; my $retval = eval ${$data->{expr}}; ${$data->{expr}} = ''; my $dumped = Dumper $retval; $dumped =~ s/^\$VAR\d+ = //; $data->{output}->insert("end", $dumped); return; }
1 2 3 4 5 6 7 8 9 10
use Data::Dumper; use Tk; my $mw = MainWindow->new()->bind('<Return>', [\&foo]); MainLoop(); sub foo { my $retval = eval '%h = (foo => q{bar}); \%h'; print Dumper $retval; }
1 2 3 4 5 6 7 8 9 10 11 12 13
use Data::Dumper; use Tk; my $foo = '%h = (foo => q{bar}); \%h'; my $mw = MainWindow->new()->bind('<Return>', [\&foo, $foo]); MainLoop(); sub foo { my (undef, $foo) = @_; my $retval = eval $foo; print Dumper $retval; }
3 Einträge, 1 Seite |