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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:13:56+00:00 2026-05-15T17:13:56+00:00

I have started learning perl and like to try out new things. I have

  • 0

I have started learning perl and like to try out new things.

I have some problem in text processing.
I have some text of the form,

0 1 2 3 4 5 6 7 8 9 10

6 7 3 6 9 3 1 5 2 4 6

I want to transpose this text. Like, I want to make rows as columns ans columns as rows. Id there a way to do this in perl?

Thank you all.

  • 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-15T17:13:57+00:00Added an answer on May 15, 2026 at 5:13 pm

    So this solution uses an array-of-arrays, each nested array
    is a row of data. Very simply you loop over the columns in each
    row and push them onto another array-of-arrays using the column
    index as the index which to push the value onto. This has the effect
    of pivoting the data as you requested.

    #!/usr/bin/env perl
    
    my @rows = ();
    my @transposed = ();
    
    # This is each row in your table
    push(@rows, [qw(0 1 2 3 4 5 6 7 8 9 10)]);
    push(@rows, [qw(6 7 3 6 9 3 1 5 2 4 6)]);
    
    for my $row (@rows) {
      for my $column (0 .. $#{$row}) {
        push(@{$transposed[$column]}, $row->[$column]);
      }
    }
    
    for my $new_row (@transposed) {
      for my $new_col (@{$new_row}) {
          print $new_col, " ";
      }
      print "\n";
    }
    

    This results in:

    0 6 
    1 7 
    2 3 
    3 6 
    4 9 
    5 3 
    6 1 
    7 5 
    8 2 
    9 4 
    10 6
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently started learning Perl and one of my latest assignments involves searching
I've been a web developer for some time now, and have recently started learning
I recently started learning Python and I was rather surprised to find a 1000
I have been dabbling in programming/scripting languages since I was a kid. I started
Ever since I started coding back in 2008 I was addicted to it and
Anyone have any idea which Resource manager is good for PVM? Or should I
I'm trying to familiarize myself with the embedded field, but also have limited resources
On my website I store user pictures in a simple manner such as: image/user_1.jpg.
In PowerShell I find myself doing this kind of thing over and over again

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.