• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 372
  • Last Modified:

split string

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
pkimk
Asked:
pkimk
1 Solution
 
ddaCommented:
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now