develooper Front page | perl.beginners | Postings from March 2002

RE: reading one character at a time

Thread Previous | Thread Next
Jonathan E. Paton
March 4, 2002 10:29
RE: reading one character at a time
Message ID:
> Is there a perl function that reads one character at
> a time from a string and and returns that character?

There are VERY FEW situations that require this kind of
action... but assuming you have one then the well proven
shortest approach is:

$string = "Hello World";
@string = $string =~ /./g;


$string = "Hello World";
for ($string =~ /./g) { print $_."\n"}

Split on a null length string is probably more readable,
but this simple technique works for pairs of characters...
and allows you to avoid pack() and unpack() a little

Take care,

Jonathan Paton

Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About