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

RE: reading one character at a time

Thread Previous | Thread Next
Nikola Janceski
March 4, 2002 10:54
RE: reading one character at a time
Message ID:
actually searching on a empty pattern is wrong wrong wrong!
a pattern in a search that evalutes to "" will use the previous successful
pattern match.

so the following:

if($x =~ /pattern/){
	print "yes\n" if($y =~ //); ## this really means if($y =~ /pattern/)
if you made it this far

man perlop; #line 1100
             If the PATTERN evaluates to the empty string, the
             last successfully matched regular expression is used

-----Original Message-----
From: Jonathan E. Paton []
Sent: Monday, March 04, 2002 1:29 PM
Subject: RE: reading one character at a time

> 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

To unsubscribe, e-mail:
For additional commands, e-mail:

The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.

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