[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] STRING2LIST conversion




  > Is there a function to load a @list with string's characters as elements:
  >                 @list= func("anystring");

  > returns $list[0]="a", .... $list[9]="g" ???

I suppose you meant $list[8] should be "g":

Try split // as in:

% perl -le '
@list= func("anystring");
print @list[0,8];
sub func { split //, $_[0] }
'
ag

  > I read getc must be avoided (SLOW!) ...

Yupp, but if you want to "eat" one character after the other and
process it immediately, something like

    $string =~ s/(.)// and $firstcharacter = $1;

might be adequate.

% perl -le '
$string = "anystring";
while ($string =~ s/(.)// and $firstcharacter = $1){
   print $firstcharacter;
}
'
a
n
y
s
t
r
i
n
g


  > Luca.post



andreas