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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:53:22+00:00 2026-06-11T20:53:22+00:00

I am relatively new to Perl. I have a reference to an array called

  • 0

I am relatively new to Perl. I have a reference to an array called $TransRef that contains references to arrays. My goal is to write a sub that takes the $TransRef arguement as its only argument, sorts the references to the underlying array by the 2nd element (a string) and sets the output back to the $TransRef reference. Can someone please show how this can be done in Perl?

Here is some code that generates $TransRef. It has not been tested yet and may have some bugs:

# Parse the data and move it into the Transactions container.
for ($Loop = 0; $Loop < 5; $Loop++)
{
   $Line = $LinesInFile[$Loop];
   # Create an array called Fields to hold each field in $Line.
   @Fields = split /$Delimitor/, $Line;  
   $TransID = $Fields[2];
   # Save a ref to the fields array in the transaction list.
   $FieldsRef = \@Fields;
   ValidateData($FieldsRef);
   $$TransRef[$Loop] = $FieldsRef;
}
SortByCustID($TransRef);

sub SortByCustID()
{
   # This sub sorts the arrays in $TransRef by the 2nd element, which is the cust #.
   # How to do this?
   my $TransRef = @_;
   ...
}
  • 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-11T20:53:23+00:00Added an answer on June 11, 2026 at 8:53 pm

    Pretty straightforward:

    sub sort_trans_ref {
        my $transRef = shift;
        @$transRef = sort { $a->[1] cmp $b->[1] } @$transRef;
        return $transRef;
    }
    

    though it would be more natural to me to not modify the original array:

    sub sort_trans_ref {
        my $transRef = shift;
        my @new_transRef = sort { $a->[1] cmp $b->[1] } @$transRef;
        return \@new_transRef;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am relatively new to Perl.I have been trying to insert data to database
I'm relatively new to Perl, writing some XML parsing scripts. I have done two
Im relatively new to the Android world but I have a quick question. I
Relatively new to JQuery. I've got some code that does a banner swap with
Im relatively new to PHP but have realized it is a powerfull tool. So
Relatively new to python. I recently posted a question in regards to validating that
Relatively new to mySQL so this is probably an easy one: I have a
Being relatively new to the software industry I have come across a question of
Let's say I have a thread: sub new { my $class = shift; my
Relatively new to PHP and I am uingd PHP to produce a table that

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.