Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Can split split against more than one character in a string of the same character?

by hippo (Bishop)
on Jul 15, 2019 at 21:17 UTC ( [id://11102894]=note: print w/replies, xml ) Need Help??


in reply to Can split split against more than one character in a string of the same character?

No need to mess with split when you just want to divide up a string of the same chars:

use strict; use warnings; use Test::More tests => 1; my $in = 'aaaaaaaaa'; my $want = 'aa aa aa aa a'; my $have = join ' ', ($in =~ /a{1,2}/g); is $have, $want;

Replies are listed 'Best First'.
Re^2: Can split split against more than one character in a string of the same character?
by Don Coyote (Hermit) on Jul 15, 2019 at 22:29 UTC

    I had an inkling that split could do this, but was approaching it from too complicated a place. Starting to get the feeling I should have perldoc -f split now.

    This is a clean and efficient way of doing this with match though, thanks

    I like the simplicity of the test structure, allowing for documenting attempts. That's really great.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-03-29 11:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found