> count only the number of spaces at the START of the line

OWTDI:

    $_ = '  test ';
    /^( *)/;  # the parens capture the match into $1
    print length $1;

---------------------------

In case you are interested, you tried:

>     my $i = () = $str =~ /^\s/;

This would print 0 or 1, depending on whether the regex matched.

$i in your approach is counting the number of chunks matched,
not the length of any of the matched chunks.

To explain this a little further, consider instead:

    my $i = () = $str =~ /^(\s)/;

This would also print 0 or 1, depending on whether the regex matched.
All I have done is added explicit capturing parens which were, in your
code, assumed by perl.

Now consider:

    my $i = () = $str =~ /^(\s)(\s)/;

This would print 0 or 2, depending on whether the regex matched,
which it would if there was at least two spaces at the start of the
line.

hth


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to