On Jul 23, Michael Dube said: >I know that tr/// will return the number of matches in a string. My attempt >below results in $inittabcount being set to 6 (wrong), while $tabcount gets >correctly set to 5. > > $test = "\t\t\tsasdfasdftill:\tin\tscope?"; > > $inittabcount = ($test =~ tr/^\t*?\w//); tr/// is NOT a regular expression. Please do not be misled into think it is. It merely does character-to-character translation. To count the number of leading (anything)s in a string, use a regex like so: $string =~ /^((?:anything)*)/; $count = length($1) / length(anything); For tabs, you'd do: $string =~ /^(\t*)/; $count = length($1); # the divided-by-1 is implicit -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun. Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/ Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/ Acacia Fraternity, Rensselaer Chapter. Brother #734 ** Manning Publications, Co, is publishing my Perl Regex book ** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How do I count the number of tabs at the beginning of a string?
Jeff 'japhy/Marillion' Pinyan Mon, 23 Jul 2001 12:47:37 -0700
- How do I count the number of tabs at the beg... Michael Dube
- Re: How do I count the number of tabs a... Paul
- Jeff 'japhy/Marillion' Pinyan