Solved

split string

Posted on 2002-05-08
1
361 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

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 explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

13 Experts available now in Live!

Get 1:1 Help Now