Re: Newbie questions, migrating from c++

From: Kåre Olai Lindbach (barbr-en_delete__at_online.no.invalid)
Date: 12/12/04


Date: Sun, 12 Dec 2004 19:25:46 +0100

On 12 Dec 2004 10:14:47 -0800, gg500@lycos.com wrote:

>K? Olai Lindbach wrote:
>> $_ = ' string with spaces first';
>> s/^\s+//;
>> print "$_\n";
>
>But the code you propose cuts the spaces from the beginning of the line
>and does not solve the problem. I was posing a problem which I needed
>to know how many spaces there were.

Sorry, I got so upset with earlier questions in this thread that I
didn't get this question/problem correctly... ;-)

use strict;

$_ = ' string with spaces first';

if(/^(\s+)/) {
  print length($1),"\n";
}

or using a decent variable name:

$atext = ' string with spaces first';

if($atext =~ /^(\s+)/) {
  print length($1),"\n";
}

This is not the most concise way, I believe.

-- 
mvh/Regards Kåre Olai Lindbach
(News: Remove '_delete_' and '.invalid')
(HTML-written email from unknown will be discarded)


Relevant Pages

  • detroit comes abegging....
    ... web site at www.abelard.org - news comment service, logic, economics ...
    (uk.politics.misc)
  • Re: [OT] Is this a valid USPS tracking number?
    ... se.edt.ericsson.se>) about 'Is this a valid USPS tracking ... >reply posing as some white thrash arsehole and then to post their ... Inland Revenue and a contact phone number within the Metropolitan ... The bad news is that everything is prohibited. ...
    (sci.electronics.design)
  • Re: Newbie questions, migrating from c++
    ... Kåre Olai Lindbach wrote: ... I was posing a problem which I needed ... but unfortunately the lack of patience leads to ... wanting to learn all at once. ...
    (comp.lang.perl.misc)

Loading