develooper Front page | perl.perl6.users | Postings from November 2017

Tip: how to each individual leading space in a line

From:
Todd Chester
Date:
November 1, 2017 09:00
Subject:
Tip: how to each individual leading space in a line
Message ID:
c167eb18-52d6-0dfa-a1b6-97cc86440a40@zoho.com
Hi All,

wander_ over on the chat line helped me figure out a
vexing problem.

I needed to replace each individual leading space
in a line.  Not remove all the leading white space or
replace it with a single character.  Each space had
to be replaced with a sequence of characters and
leave the spaces between character alone.


  $ perl6 -e 'my $x="  abc   d   e "; $x ~~ s:g/^^(" ")+ 
/{" "x$/[0].elems}/; say $x;'

   abc  d   e


My head is still spinning those guys are so smart...

-T



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About