?
Solved

split string

Posted on 2002-05-08
1
Medium Priority
?
367 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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
Suggested Courses

777 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