Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How to get Incremental charecter groups in a string

by Jasper (Chaplain)
on Jun 19, 2006 at 16:24 UTC ( #556280=note: print w/ replies, xml ) Need Help??


in reply to How to get Incremental charecter groups in a string

$_ = "this abc xyz abbc donut ghijkl"; "abcdefghijklmnopqrstuvwxyz" =~ $_ and print for split;
This approaches it from a slightly different angle, and removes the false positive 'abbc' results that you get from the $_ eq join sort split method...
You can add a /i in there if you wanted to ignore case.. :S


Comment on Re: How to get Incremental charecter groups in a string
Download Code
Re^2: How to get Incremental charecter groups in a string
by GrandFather (Cardinal) on Jun 19, 2006 at 20:58 UTC

    It's not clear that 'abbc' is a false positive, and it is not clear that skipping 'is' (as your code does) is appropriate. However the following fixes the supposed false positive and retains the possibly desired 'is':

    use strict; use warnings; my $str="this is abc and bcf and xyz and ijklmn but not abbc"; my @words = split ' ', $str; my @incWords = grep { my %uniq = map {$_ => 0} split ''; $_ eq join '', sort keys %uni +q } @words; print "@incWords";

    Prints:

    is abc bcf xyz ijklmn not

    DWIM is Perl's answer to Gödel
      Yes, well, yes, indeed, that does do what you say it does, but who knows what the OP wanted except the OP?

      All I was showing was TMTOWTDI. Maybe. :)

        I did like your trick of turning the regex inside out to check for incrementing runs of letters, but 'bcf' from OP's example argues against that being what is required. Nice trick though. :)


        DWIM is Perl's answer to Gödel
Re^2: How to get Incremental charecter groups in a string
by ikegami (Pope) on Jun 20, 2006 at 15:54 UTC
    Nice, but it would be faster to use index:
    index('abcdefghijklmnopqrstuvwxyz', $_) >= 0 and print for split;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://556280]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-07-23 06:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (133 votes), past polls