in reply to Re^2: How to enter a MAC address
in thread How to enter a MAC address

    "... learning perl and tk as I go"

Well, I'm impressed.  Learning Perl takes enough effort (though mostly fun :-D), and Tk is no simple discipline to master.  Good for you!

If you want to display hexadecimal, you could just use sprintf to reformat each hex pair before the assignment:

$mw->Entry(-textvariable => [ sprintf "%02x", $addy[$i] ], -width => 3 +) ->pack(-side => 'left');

Another minor suggestion:  check your loop variable so you don't print an extra ':' after the final byte:

if ($i < 5) { $mw->Label(-text => ':', -width => 1)->pack(-side => 'left'); }

s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Replies are listed 'Best First'.
Re^4: How to enter a MAC address
by snotnose (Novice) on Feb 15, 2007 at 00:00 UTC
    I'm close. How do I validate my entry? I need either 1 or 2 hexadecimal characters. I've got 6 entry widgets, 1 per byte. Each treats it's contents as a string. I'm validating on focusout. So far none of my regex's has worked, the naive version was:
    -validatecommand => sub{$_[0] =~ /\x/},
    Gee, hung up on a regex. Whoodathunk? :)

    I've got 1 other problem. The first entry widget doesn't have focus when it starts, I have to hit tab first. How do I fix this?

      Update:  After re-reading the documentation, I see that what I originally suggested is wrong.  \xnn matches "the character whose numeric value is nn", where "nn" is a pair of hex digits.

      I think that /\x/ will only guarantee you that you have 1 hex digit in your string, though won't work.  If you want to make sure there are exactly 2 hex digits, use something like:

      -validatecommand => sub{$_[0] =~ /^[0-9a-f]{2}$/i},

      The ^ matches the beginning of the line, the $ matches the end, and the {2} matches exactly 2 hex digits (0-9 or a-f).  The i at the end causes ignoring of case, of course.

      Check perlre if you need to read up on regexes.  Good luck!


      s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/