Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: How Do You Parse a Line After Each Character?

by jjhorner (Hermit)
on Jul 11, 2000 at 22:44 UTC ( [id://22065]=note: print w/replies, xml ) Need Help??


in reply to How Do You Parse a Line After Each Character?

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/

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://22065]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-26 06:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found