我对 Perl 比较陌生。我有一个名为 $TransRef 的数组的引用,其中包含对数组的引用。我的目标是编写一个将 $TransRef 参数作为其唯一参数的子程序,按第二个元素(字符串)对底层数组的引用进行排序,并将输出设置回 $TransRef 引用。有人可以展示如何在 Perl 中完成此操作吗?
下面是一些生成 $TransRef 的代码。它尚未经过测试,可能存在一些错误:
# 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 = @_;
...
}