This is the package itself: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 += 1 +0) { 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($te +n, $this_char, 1) : "."; } print $numbers; print " " x (60 - length $numbers); print " " x 5; print $chars; print "\n"; } } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Is there any garbage chars in your data?
by cchampion (Curate) on Mar 26, 2003 at 00:04 UTC | |
by merlyn (Sage) on Mar 26, 2003 at 04:07 UTC | |
by pg (Canon) on Mar 26, 2003 at 17:54 UTC |