From the Perl Cookbook, 1.5:
# break into individual characters
my @characters = split(//);
# or if you want ASCII values
my @characters = unpack("C*");
# of if you wish to use a loop
while (/(.)/g) { # . is never a newline
# do something with $1
}
For a real world example, also from the
Perl Cookbook (modified slightly):
my %seen = ();
my $string = "J. J. Horner is so cool!";
foreach my $byte (split //, $string) {
$seen{$byte}++;
}
print "unique chars are: ", sort(keys %seen), "\n";
Which yeilds: unique chars are: !.HJceilnors
J. J. Horner
Linux, Perl, Apache, Stronghold, Unix
jhorner@knoxlug.org http://www.knoxlug.org/