[comp.lang.perl] Changing first character of a string

markb@agora.uucp (Mark Biggar) (06/30/90)

In article <sean.646705830@s.ms.uky.edu> sean@ms.uky.edu (Sean Casey) writes:
>Does anyone know of a better way to change the first character of string
>$flags to 'S'? The only way I've figured out so far is:
>
>	$flags =~ s/(.)(.*)/S$2/;
>
>Gotta be a better way.

substr($flag,0,1) = 'S';
$flag =~ s/^./S/;
$flag = 'S' . substr($flag,1,65535);
@flag = split(//,$flag);shift @flag;unshift(@flag,'S');$flag = join('',@flag);

last one :-)

Perl's maternal uncle
Mark Biggar