develooper Front page | perl.perl6.language | Postings from May 2005

Re: split /(..)*/, 1234567890

Thread Previous | Thread Next
From:
Uri Guttman
Date:
May 12, 2005 10:12
Subject:
Re: split /(..)*/, 1234567890
Message ID:
x78y2ks70l.fsf@mail.sysarch.com
>>>>> "JSD" == Jonathan Scott Duff <duff@pobox.com> writes:

  JSD> To bring this back to perl6, autrijus' original query was regarding

  JSD> 	$ pugs -e 'say join ",", split /(..)*/, 1234567890'

  JSD> which currently generates a list of ('','12','34','56','78','90')
  JSD> In perl5 it would generate a list of ('','90') because only the last
  JSD> pair of characters matched is kept (such is the nature of quantifiers
  JSD> applied to capturing parens). But in perl6 quantified captures put all
  JSD> of the matches into an array such that "abcdef" ~~ /(..)*/ will make
  JSD> $0 = ['ab','cd','ef']. 

  JSD> I think that the above split should generate a list like this:

  JSD> 	('', [ '12','34','56','78','90'])

i disagree. if you want complex tree results, use a rule. split is for
creating a single list of elements from a string. it is better keep
split simple for it is commonly used in this domain. tree results are
more for real parsing (which split is not intended to do) so use a
parsing rule for that.

also note the coding style rule (i think randal created it) which is to
use split when you want to throw things away (the delimiters) and m//
when you want to keep thinks.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org

Thread Previous | Thread Next


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