in reply to iterating through scalar

See substr to access single characters.

But the "usual" way is

for my $c (split //, $string) { print $c; }

Update

Alternatively:

while ( $string =~ m/(.)/g ){ print $1; }

update
made code clearer

Cheers Rolf

PS: Je suis Charlie!

Replies are listed 'Best First'.
Re^2: iterating through scalar
by AnomalousMonk (Archbishop) on Feb 06, 2015 at 19:46 UTC

    Also:

    c:\@Work\Perl\monks>perl -wMstrict -le "my $string = 'foobar'; ;; for my $offset (0 .. length($string) - 1) { printf qq{'%s' }, substr $string, $offset, 1; } " 'f' 'o' 'o' 'b' 'a' 'r'


    Give a man a fish:  <%-(-(-(-<