Solved

split string

Posted on 2002-05-08
1
362 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
1 Comment
 
LVL 4

Accepted Solution

by:
dda earned 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl count the hash for print 4 161
pattern matching in perl 2 101
Rename file based on contents in the file? 3 80
Perl Scripting from a shell script with if and for 4 82
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…
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…

932 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

11 Experts available now in Live!

Get 1:1 Help Now