Solved

Perl: Split string into sets of characters without delimiter

Posted on 2010-08-31
3
369 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
  • 2
3 Comments
 
LVL 84

Accepted Solution

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

Assisted Solution

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

Author Closing Comment

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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

816 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now