Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Split string after 14 Line Feeds? (//g)

by tye (Sage)
on Dec 03, 2012 at 23:17 UTC ( #1006962=note: print w/replies, xml ) Need Help??


in reply to Split string after 14 Line Feeds?

my @chunks = $description =~ /^((?:[^\n]*\n){14}|.*)*/gs;

- tye        

Replies are listed 'Best First'.
Re^2: Split string after 14 Line Feeds? (//g)
by johnfl68 (Beadle) on Dec 04, 2012 at 05:11 UTC
    Thanks. I think I see where you are going with this, but the array is coming up empty. I'll try and go over it again, regex's make my head hurt. :(

      Indeed. I conflated two similar techniques: getting a list of matches from /(...)/g and getting a list of matches from /(...)(...)(...)/. You don't get a list of matches from /(...)*/ (nor from /(...)*/g).

      What I should have written was:

      my @chunks = $description =~ /\G((?:[^\n]*\n){14}|.+)/gs;

      (tested even; works even)

      Update: Changed last * to + to eliminate extra empty string in result that I just noticed which is due to "quirk" in Perl regex processing (something I think we should just 'fix', but that is a story for another node, one I've written at least once already).

      - tye        

        Thank you very much! That works great!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1006962]
help
Chatterbox?
[Corion]: marto: Yeah - their mother picked all three of them up at the kindergarden to then go to the hospital, and all three of them were well behaved, and all also were quite obedient when they came home, so they recognized the situation
[Corion]: Nice to see that the kids have some understanding of important things that happen and the appropriate behaviour :)
[marto]: at times mine surprise me with this behavior :)
[Corion]: I mean, in a way it would be nicer+easier if they always where that obedient, but it's comforting to see that they are when it matters, at least for now ;)

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2016-12-08 09:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (138 votes). Check out past polls.