use StringInspector; use strict; my $inspector = new StringInspector; $inspector->inspect("abcdefghijkl"); $inspector->display(); #### package StringInspector; use Hash::Util qw(lock_keys); use strict; sub new { my $self = {}; $self->{SUSPECT} = ""; bless $self; lock_keys(%{$self}); return $self; } sub inspect { my ($self, $string) = @_; $self->{SUSPECT} = $string; } sub display { my $self = shift; for (my $index = 0; $index <= length $self->{SUSPECT}; $index += 10) { my $ten= substr($self->{SUSPECT}, $index, 10); my $numbers = ""; my $chars = ""; for (my $this_char = 0; $this_char < length $ten; $this_char ++) { my $ascii = ord(substr($ten, $this_char, 1)); $numbers .= sprintf("0x%0x ", $ascii); $chars .= (($ascii >= 32) && ($ascii <= 126)) ? substr($ten, $this_char, 1) : "."; } print $numbers; print " " x (60 - length $numbers); print " " x 5; print $chars; print "\n"; } } 1;