in reply to first char of string?

Since everyone has given the direct answer, here a few other ways of doing it:

Regex:

$string =~ m!^(.).+$!;
my $first = $1;

Split:

my @list = split('', $string); # I can't recall if '' works
$list[0]; # but I think that is right.

Really funky:

$string = reverse($string);
my $char = chop $string;
# and if you need the string intact still
$string .= $char;
$string = reverse($string);

There is more than one way to do it.

Replies are listed 'Best First'.
RE: Re: first char of string?
by Anonymous Monk on Mar 14, 2000 at 19:28 UTC
    you could do it even shorter: ($char) = split("",$string);