?
Solved

Perl: Split string into sets of characters without delimiter

Posted on 2010-08-31
3
Medium Priority
?
415 Views
Last Modified: 2012-05-10
Hi,

I would like to split a string into sets of characters without the help of a delimiter. For example if I have a random string like this one:
my $str = "1101111000110000001110110111";
I'd like to split it into sets of four characters, so 0-3, 4-7, 8-11, etc and then process them in a loop like foreach.

How can I do this?
0
Comment
Question by:php-newbie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 2000 total points
ID: 33565567
my $str = "1101111000110000001110110111";
for( unpack"(a4)*",$str ){
   print;
}
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 2000 total points
ID: 33565579
while ( $str=~/(....)/g  ){ print $1; }  
0
 

Author Closing Comment

by:php-newbie
ID: 33565627
awesome, thanks!!!!!!!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question