Uri Guttman wrote: >>>>>> "CC" == Chuck Crisler <charles.cris...@comcast.net> writes: > > CC> How do I access specific character positions in a scalar string? In case > CC> it makes any difference, I specifically want to test the zeroth > CC> character. Something like the following. > > CC> my $str = "abc"; > CC> if ($str[0] == '#') > CC> { > CC> do something... > CC> } > > you already found substr. but i will guess your real need isn't to scan > a string char by char or to directly index for a char. my suspicious > nose tells me you are parsing a string and substr is the wrong way to do > it. regexes will get you each char or more very easily. or you can split > the string and loop over it that way. but calling substr for each char > is clumsy and slow. if you want to know that the string begins with a > char, this regex will do: > > $str =~ /^a/ > > so ask your real question about string munging and not how to do a > particular technique.
Searching "crisler" in the archives results in four messages. I believe he was trying, and his original question was a real question. > this is called the XY problem where you think you > want X but you really want Y. newbs don't understand that, without simple code examples. 'jwkrahn'++. Steve
smime.p7s
Description: S/MIME Cryptographic Signature