if you just want 1 letter per element then simply do
$string = 'hello';
@array = split(//, $string);
hope this helps
-bn
-----BEGIN PERL GEEK CODE BLOCK-----
Version: 0.01
P+>+++( )$c->++P6 R++>+M >+$O
>++MA+>++E >+PU >++BD
>+++C+$D++$S+++>++++$X!WP+> (
)MO!PP++++n+>++CO-->+++PO-o >++G >+++A
>+++OL!OLC+>++OLR+>++Ee!Ev!Eon+uL+++>*$
uB+$uS+$uH+$uo+$w-->---m!
------END PERL GEEK CODE BLOCK------
| [reply] [d/l] |
You can use global matching /./g to process N chars at-a-time.
#!/usr/bin/perl -wT
use strict;
my $string = 'AGTCGTCGATGCTGATGCTAGCCCC';
print "one at-a-time: $_\n" for $string =~ /./g;
print "two at-a-time: $_\n" for $string =~ /.{1,2}/g;
print "six at-a-time: $_\n" for $string =~ /.{1,6}/g;
__END__
=head1 OUTPUT
one at-a-time: A
one at-a-time: G
one at-a-time: T
one at-a-time: C
one at-a-time: G
one at-a-time: T
one at-a-time: C
one at-a-time: G
one at-a-time: A
one at-a-time: T
one at-a-time: G
one at-a-time: C
one at-a-time: T
one at-a-time: G
one at-a-time: A
one at-a-time: T
one at-a-time: G
one at-a-time: C
one at-a-time: T
one at-a-time: A
one at-a-time: G
one at-a-time: C
one at-a-time: C
one at-a-time: C
one at-a-time: C
two at-a-time: AG
two at-a-time: TC
two at-a-time: GT
two at-a-time: CG
two at-a-time: AT
two at-a-time: GC
two at-a-time: TG
two at-a-time: AT
two at-a-time: GC
two at-a-time: TA
two at-a-time: GC
two at-a-time: CC
two at-a-time: C
six at-a-time: AGTCGT
six at-a-time: CGATGC
six at-a-time: TGATGC
six at-a-time: TAGCCC
six at-a-time: C
-Blake
| [reply] [d/l] [select] |
| [reply] [d/l] |
@results = split (/\s*/,$string);
matches zero or more times
Have a nice day
All decision is left to your taste | [reply] [d/l] |
there is something magical about split. when used as my @chars = split //, $word;, it will split on each character, including a null field for each leading whitespace character. when used as my @chars = split '', $word;, it will split on each character without creating leading null fields.
this may not be applicable to your data, but i thought it's something you would want to know.
~Particle
| [reply] [d/l] [select] |
Just one alternative chunk of code, without using split:
You can use unpack and obtain one array which contains the ascii values of the strings:
unpack "C*",$str
And you can obtain the chars as follow
@a=map chr,unpack "C*",$str;
Hopes
$_=$,=q,\,@4O,,s,^$,$\,,s,s,^,b9,s,
$_^=q,$\^-]!,,print
| [reply] [d/l] [select] |