http://www.perlmonks.org?node_id=78650


in reply to Spliting letters in a string

I would do this with a hash:

#!/usr/bin/perl -w my $str = "abcdefg"; my %hash; %hash = map {$_ => $_} split //, $str; print qq{$_ => $hash{$_}\n} for sort keys %hash;

When run:

# ./t.pl a => a b => b c => c d => d e => e f => f g => g

Cheers,
KM