John, Thanks and thanks :)
Emeka On Mon, Aug 1, 2011 at 2:45 PM, John W. Krahn <jwkr...@shaw.ca> wrote: > Emeka wrote: > >> Hello All, >> > > Hello, > > > I would like to know how to access character from string lateral. >> >> Say I have >> $foo = "From Big Brother Africa"; >> I would want to print each of the characters of $foo on its own. >> >> In some languages string type is just array/list of characters. What is it >> in Perl? >> > > A string. > > In Perl there are a few ways to do what you want: > > $ perl -le'my $foo = "From Big Brother Africa"; print for split //, $foo' > F > r > o > m > > B > i > g > > B > r > o > t > h > e > r > > A > f > r > i > c > a > $ perl -le'my $foo = "From Big Brother Africa"; print for $foo =~ /./sg' > F > r > o > m > > B > i > g > > B > r > o > t > h > e > r > > A > f > r > i > c > a > $ perl -le'my $foo = "From Big Brother Africa"; print for map substr( $foo, > $_, 1 ), 0 .. length( $foo ) - 1' > F > r > o > m > > B > i > g > > B > r > o > t > h > e > r > > A > f > r > i > c > a > $ perl -le'my $foo = "From Big Brother Africa"; print for unpack "(a)*", > $foo' > F > r > o > m > > B > i > g > > B > r > o > t > h > e > r > > A > f > r > i > c > a > > > > > > John > -- > Any intelligent fool can make things bigger and > more complex... It takes a touch of genius - > and a lot of courage to move in the opposite > direction. -- Albert Einstein > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > > -- *Satajanus Nig. Ltd *