in reply to How Do You Parse a Line After Each Character?
From the Perl Cookbook, 1.5:
For a real world example, also from the Perl Cookbook (modified slightly):# 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 }
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/
|
|---|