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

RE: reading one character at a time

Thread Previous | Thread Next
From:
Jonathan E. Paton
Date:
March 4, 2002 10:29
Subject:
RE: reading one character at a time
Message ID:
20020304182859.41990.qmail@web14604.mail.yahoo.com
> 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;

OR:

$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
longer!

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
http://uk.my.yahoo.com

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About