Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion number of starting tabs
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
J. Gleixner  
View profile  
 More options Aug 16 2012, 4:51 pm
Newsgroups: comp.lang.perl.misc
From: "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
Date: Thu, 16 Aug 2012 15:51:29 -0500
Local: Thurs, Aug 16 2012 4:51 pm
Subject: Re: number of starting tabs
On 08/16/12 15:07, George Mpouras wrote:

> I want to count the number of staring tabs of a string. Is there any
> better way than

> my $var = ' foo ';
> (my $tabs = $var) =~s/^(\t*).*$/$1/; $tabs = length $tabs;
> print $tabs; # 2

Avoid doing a substitute/replace and just capture them:

my ( $tabs ) = $var =~ /^(\t+)/;
print "Number of tabs:", length( $tabs ), "\n";


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.