Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Break string into a list

Status
Not open for further replies.

MonsterAar

Programmer
Aug 16, 2006
24
0
0
AU
What I need to do is take a string, for example $string and whenever there is a capital, form an entry in a list.

To illustrate what I meen:

If i have this string: Os6NaClPo9C
I want to break it into a list with the following elements:
Os6
Na
Cl
Po9
C

any ideas?
 
Try this:
Code:
my @list = split /(?=[A-Z])/, $string;
 
This works too:

my @elements;
my $string = 'Os6NaClPo9C';
(@elements) = $string=~/([A-Z][^A-Z]*)/g;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top