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 7789697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:22:40+00:00 2026-06-01T21:22:40+00:00

I have an array where the elements look like this (whitespaces included) @array =

  • 0

I have an array where the elements look like this (whitespaces included)

@array = (
"    795     0|  1",
"      5   135| 17",
"     12   161| 17",
"    244    22| 17",
"     11    25| 17",
"    249   389| 17",
"  22383   443| 17"
);

I need to take an element out

"    795     0|  1"

and split it into 3 numbers getting rid of the white spaces and “|” in each line.

@new_array =("795","0","1");

The problem I’m having is that the whitespace and size of the numbers varies.

  • 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-01T21:22:42+00:00Added an answer on June 1, 2026 at 9:22 pm

    I would use a regexp matching only the numbers:

    #!/usr/bin/perl
    
    use strict ;
    use warnings ;
    use Data::Dumper ;
    
    my @array = (
    "    795     0|  1",
    "      5   135| 17",
    "     12   161| 17",
    "    244    22| 17",
    "     11    25| 17",
    "    249   389| 17",
    "  22383   443| 17"
    );
    
    foreach my $item ( @array ) {
      my @tmp = $item =~ m/(\d+)/g ;
      printf "'%s' => %s\n" , $item , Dumper( \@tmp ) ;
    }
    

    This will also work if the string has no whitespace in the beginning.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several input elements which look like this: <input type=radio checked=checked value=1 name=handle[123]
I have an array with 16 elements. I would like to evaluate these to
An array is defined of assumed elements like I have array like String[] strArray
I have an array on javascript and i insert the elements on it like
So I have an array of numbers that look something like 1,708,234 2,802,532 11,083,432
I have an XML File with Elements that look like the following: <level> <name>Name
I have a PHP array that I'd like to duplicate but only copy elements
I have this table, from which i'd like to select all the td elements
I have an array like this Array['one','two','three','four','five'] and I have an array like this
I have 2 arrays that look like this: $array1 = [ ['id' => '434b5g6',

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.