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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:01:07+00:00 2026-05-28T20:01:07+00:00

I have a data file like a two-dimensional array 22950 12 80044 22 02942

  • 0

I have a data file like a two-dimensional array

22950   12
80044   22
02942   06
42018   20
63829   10
...

I want to shuffle this array into a random order, like

42018   20
22950   12
...

Looks like the ‘shuffle’ in List can be used to shuffle a vector, how to keep handle this kind of two-dimensional array?

  • 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-05-28T20:01:08+00:00Added an answer on May 28, 2026 at 8:01 pm

    Since you are only shuffling the first dimension of the array, List::Util::shuffle will work without any modification.

    Perl does not have multi-dimentional arrays, it has arrays of scalars, each of which can also be an array. This is effectively a multi-dimentional array, but it means that you can use normal array operations like shuffle, since shuffle does not care what the values of the array are (and in this case they will be other arrays).

    so the line:

    my @random = shuffle \@array1, \@array2, \@array3;
    

    is the same as

    my @random = shuffle 1, 2, 3;
    

    as far as shuffle is concerned (a list of 3 elements to shuffle).

    so assuming your 2D data is contained in the array @data

    my @data = (
        [1234, 34],
        [4564, 45],
        ...
    );
    

    then you would just write:

    use List::Util 'shuffle';
    my @random = shuffle @data;
    

    and then you would access the 2D structure normally:

    say $random[0][1];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the file data.txt with two columns and N rows, something like this:
I have two question : I have a data on binary file. I want
I have two excel files. The first excel file is like this: 12 A
I have a data file that looks like the following example. I've added '%'
I have a file data.base which looks like: 1234 XXXX 4321 XXXX 9884 ZZZZ
Hi i have a yaml file like so --- data: - date: 2004-06-11 description:
I have a very large XML file which has like 40000 data, and when
I have a program that reads data from a file line-by-line. I would like
Say I have a data file that I want to process; I want to
I have an xml data file and I want to populate a listview in

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.