[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

split string

Posted on 2002-05-08
1
Medium Priority
?
370 Views
Last Modified: 2012-06-21
Hi;

I have a string "1234200202020020590010001020",
How to split it into ...
1234 20020202002059 001 0001 020
and assign into different variable according to the length.

If the string is "1234,20020202002059,001,0001,020",
How to split it into ...
1234 20020202002059 001 0001 020
and assign into different variable in a loop.


Cheers;
0
Comment
Question by:pkimk
[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
1 Comment
 
LVL 4

Accepted Solution

by:
dda earned 200 total points
ID: 6996267
Here is one of the possible ways:

use strict;

my $s1 = "1234200202020020590010001020";

my @s1 = unpack "A4 A14 A3 A4 A3", $s1;
foreach (@s1) {
    print "$_ ";
}
print "\n";

my $s2 = "1234,20020202002059,001,0001,020";
my @s2 = split /,/, $s2;
foreach (@s2) {
    print "$_ ";
}
print "\n";
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
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

649 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