in reply to counting leading white spaces

Perhaps tr?
$_ = " \ta"; print tr/ \t/ \t/; # prints "5"

Or count and delete:

$_ = " \ta"; print tr/ \t//d, $_; # prints "5a"

Replies are listed 'Best First'.
Re^2: counting leading white spaces
by almut (Canon) on Feb 11, 2009 at 20:29 UTC

    A problem with tr/// could be that it would count all occurrences, not only leading ones...

      Good point; bad oversight on my part. Below, I take extra effort to count only leading spaces...

      use strict; use warnings; AUTOLOAD{$.=0;$_=@_[$??$;:$.];@_=reverse split//;++$.while+pop=~m,\s,;y, , ,s,warn$.,$_,$/}&* ($_)for(<DATA>) __DATA__ Initiate Novice Acolyte Sexton Beadle Scribe Monk Pilgrim Friar Hermit Chaplain Deacon Curate Priest Vicar Parson Prior Monsignor Abbot Canon Chancellor Bishop Archbishop Cardinal Sage Saint Apostle Pope

      See also JAPH at the firing range