Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8727051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:22:03+00:00 2026-06-13T08:22:03+00:00

I have a numerical string: 13245988 I want to split before and after consecutive

  • 0

I have a numerical string:

"13245988"

I want to split before and after consecutive numbers.

Expected output is:

1
32
45
988

Here is what I’ve tried:

#!/usr/bin/perl
use strict;
use warnings;

my $a="132459";
my @b=split("",$a);
my $k=0;
my @c=();
for(my $i=0; $i<=@b; $i++) {
    my $j=$b[$i]+1;
    if($b[$i] == $j) {
        $c[$k].=$b[$i];
    } else {
        $k++;
        $c[$k]=$b[$i];
        $k++;
    }
}
foreach my $z (@c) {
    print "$z\n";
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:22:04+00:00Added an answer on June 13, 2026 at 8:22 am

    Editing based on clarified question. Something like this should work:

    #!/usr/bin/perl
    use strict;
    use warnings;
    
    my $a = "13245988";
    my @b = split("",$a);
    
    my @c = ();
    push @c, shift @b; # Put first number into result.
    
    for my $num (@b) { # Loop through remaining numbers.
    
        my $last = $c[$#c] % 10; # Get the last digit of the last entry.
    
        if(( $num <= $last+1) && ($num >= $last-1)) {
            # This number is within 1 of the last one
            $c[$#c] .= $num; # Append this one to it
        } else {
            push @c, $num; # Non-consecutive, add a new entry;
        }
    }
    
    foreach my $z (@c) {
        print "$z\n";
    }
    

    Output:

    1
    32
    45
    988
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming I have a numerical string: var foo = 0; Assume I want to
After I have selected a range containing numerical values, I want to, via VBA,
I have a string 1.5(+1.2/-0.5) . I want to use Regex to extract numerical
I have this string: 467:some-text-here-1786 How can I select only the first numerical value
I have an ARFF file containing 14 numerical columns. I want to perform a
I have a string: {0:16970861903381446063,length:1} I tried converting it to an object using the
I have a string errMsg to be printed after an input file is read.
If I output the string before adding it as a text node to the
I have inherited a template to convert a string to a numerical value, and
I have tried to convert an ascii string to an escaped pseudo unicode escaped

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.