Solved

Perl: Split string into sets of characters without delimiter

Posted on 2010-08-31
3
351 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
Comment Utility
my $str = "1101111000110000001110110111";
for( unpack"(a4)*",$str ){
   print;
}
0
 
LVL 84

Assisted Solution

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

Author Closing Comment

by:php-newbie
Comment Utility
awesome, thanks!!!!!!!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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 demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

14 Experts available now in Live!

Get 1:1 Help Now