As always, comments and suggestions for improvement welcome.#!c:/perl/bin/perl -w use Tk; use Tk::DialogBox; use strict; sub convert_hex; sub convert_char; my $main = new MainWindow(-title => 'Hex2Char - Char2Hex'); my (@splithex, @splitchar); my ($val, $value); my $leftframe = $main->Frame(); $leftframe->pack(-side => 'left'); my $rightframe = $main->Frame(); $rightframe->pack(-side => 'right'); $leftframe->Label(-text => "Hex")->pack(); my $hexval = $leftframe->Entry(-width => '30')->pack(); my $buttonleft = $leftframe->Button(-text => '>>', -command => sub{convert_hex;})->pack(); $rightframe->Label(-text => "Char")->pack(); my $charval = $rightframe->Entry(-width => '30')->pack();; my $buttonright = $rightframe->Button(-text => '<<', -command => sub{convert_char;})->pack(); my $exit = $main->Button(-text => 'Exit', -command => sub{exit;}); $exit->pack(-side => 'bottom'); MainLoop; sub convert_hex { my @charconv = (); my $hexvals = $hexval->get; @splithex = split(' ', $hexvals); foreach $value (@splithex) { $val = pack "H*", $value; push @charconv, "$val"; } my @switch = reverse @charconv; $charval->delete(0, 'end'); map {$charval->insert(0,$_)} @switch; } sub convert_char { my @hexconv = (); my $charvals = $charval->get; @splitchar = split(//, $charvals); foreach $value (@splitchar) { $val = unpack "H*", $value; push @hexconv, "$val "; } my @switch = reverse @hexconv; $hexval->delete(0, 'end'); map {$hexval->insert(0,uc $_)} @switch; }
cheers, -semio
In reply to Perl/TK hex2char - char2hex convertor by semio
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |