in reply to splitting a word
Although it's probably best to use the function that fits the situation the most (being substr() in this instance). The reason that split didn't work is that it was being used incorrectly. The split() function splits a string (the second argument) according to the delimiter supplied in the first argument, returning a list of strings.use strict; my $fname = 'Larry'; my $fi = substr($fname, 0, 1); # $fi = 'L' my ($fi) = $fname =~ /^(.)/; # $fi = 'L' my $fi = (split //, $fname)[0]; # $fi = 'L'
broquaint
|
|---|