Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^4: cleaving a sequence with specific alphabets

by tachyon-II (Chaplain)
on May 21, 2008 at 16:30 UTC ( [id://687795]=note: print w/replies, xml ) Need Help??


in reply to Re^3: cleaving a sequence with specific alphabets
in thread cleaving a sequence with specific alphabets

This is broken, not optimised. The .*? was there for a reason.

$string = "RYOURPOSTBROKEN";

Replies are listed 'Best First'.
Re^5: cleaving a sequence with specific alphabets
by ikegami (Patriarch) on May 21, 2008 at 17:00 UTC
    That snippet shows that yours is broken too. It doesn't return the last segment ("EN").
    my $string = "RYOURPOSTBROKEN"; print("input: $string\n"); print("expecting: R YOURPOSTBR OK EN\n"); print("\n"); { # mwah (split) my $re = qr/(?<=[KR])(?!P)/; my @arr = split $re, $string; print("split $re: @arr\n"); } { # tachyon-II (re) my $re = qr/(.*?[KR])(?!P)/s; my @arr = $string =~ /$re/g; print("$re: @arr\n"); } { # mwah (re) my $re = qr/[^KR]+.(?!P)/s; my @arr = $string =~ /$re/g; print("$re: @arr\n"); }
    input: RYOURPOSTBROKEN expecting: R YOURPOSTBR OK EN split (?-xism:(?<=[KR])(?!P)): R YOURPOSTBR OK EN (?s-xim:(.*?[KR])(?!P)): R YOURPOSTBR OK (?s-xim:[^KR]+.(?!P)): YOU POSTBR OK EN (?s-xim:[^KR]*.(?!P)): R YOU POSTBR OK EN

      Oh well, I made a mistake (better really test the code next time).

      I couldn't come up with a solution dropping the .*?, so Tachyon-II's solution only needs a slight modification ...

      ... my @arr = $string =~ / .*? [KR] (?!P) | [^KR]+$ /gx; ...

      ... for getting the strings tail.

      Thanks for checking this!

      Regards

      mwa

        That'll learn me ;-) Testing OPs code and not my own! Thanks for fixing it and pointing out you don't need the ( ).

        cheers

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-19 03:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found