in reply to How to get each character in string value

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @letters = unpack( "(a)*", 'Hello World' ); print Dumper \@letters; __END__ Output:$VAR1 = [ 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd' ];

hth,
PooLpi

'Ebry haffa hoe hab im tik a bush'. Jamaican proverb

Replies are listed 'Best First'.
Re^2: How to get each character in string value
by spmlingam (Scribe) on Dec 02, 2008 at 11:06 UTC
    If you want the output as array, you can use split and unpack, otherwise you can use pattern matching with /g flag in a while loop.
    example with unpack & character by character processing
    $string="Hello World"; $sum = 0; foreach $ascval (unpack("C*", $string)) { $sum += $ascval; } print "sum is $sum\n"; # prints "1052"