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

Re: reading one character at a time

Thread Previous | Thread Next
From:
Shawn
Date:
March 4, 2002 02:05
Subject:
Re: reading one character at a time
Message ID:
043301c1c364$13f39140$b100a8c0@work
> Is there a perl function that reads one character at a time from a
> string and and returns that character? Something like the following:
> $Line = some string;
> foreach ($Line){
> $char=read_char($_);}
>
> Thanks,
> Dick Fell

I am not positive what you are really wanting here...

my $Line = some string;
for(split(//,$Line)) {
  my $char=$_;
}

But maybe you want to be able to access those characters again later on, in which case

my $Line = some string;
my @array=split(//,$Line);
for(@array) {
  my $char=$_;
}

I am assuming you will have some additional functionality inside the for loop since $char will be
re-written by $_ on every pass.

Shawn


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