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

Re: reading one character at a time

Thread Previous | Thread Next
March 4, 2002 02:05
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? 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.


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