Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Perl: Split string into sets of characters without delimiter

Posted on 2010-08-31
3
Medium Priority
?
431 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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

604 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