#!/usr/bin/perl
# Idiom #321 Access character in string, by index

# https://w...content-available-to-author-only...s.org/idiom/321/access-character-in-string-by-index
# 

use v5.10;

use open qw( :std :utf8 );

my $s;
my @chars;

use utf8;

say "Using utf8:";
$s = '01ā3€5';
say "the input string is: ", $s;
say "it's length is: ", length $s;
@chars = split //, $s;
foreach my $i (0..$#chars) {
    printf "the %dth character is %s\n", $i, substr $s, $i, 1;    
}

say '-' x 10;

no utf8;
$s = '01ā3€5';
say "Without using utf8:";
say "the input string is: ", $s;
say "it's length is: ", length $s;
@chars = split //, $s;
foreach my $i (0..$#chars) {
    printf "the %dth character is %s\n", $i, substr $s, $i, 1;    
}


