Questions tagged [arrayref]
25 questions
0
votes
2 answers
Sorting a reference to an array of rows where each row is stored as a hash
I'm trying to sort the following data structure in Perl, by location_id.
my $employees = $dbh->selectall_arrayref(qq[
SELECT name, type, code, emp_cat_id,
percentage, location_id
FROM table_1
],{ Slice => {} });
for my $row…

ComputersAreNeat
- 175
- 1
- 1
- 11
0
votes
1 answer
Perl array reference always rewrites over itself in a loop
I am trying to read some numbers from a text file and store it as a 2 dimensional array. I read a line and push into another array as an array reference. But I noticed that main array only has last line in all rows. How can i correct this? Thanks in…

xcvbnm
- 69
- 9
0
votes
1 answer
Access array element in Perl
Dumper(@releases) has the following
$VAR1 = '\projects\proj mypac : test / 04.00.00; 0';
When I do print ( $releases[0]) it gives
\projects\proj mypac : test / 04.00.00; 0
I want individual elements like
$releases[0] =…

Yamuna
- 71
- 1
- 2
- 13
0
votes
1 answer
Number of rows in scalar - Perl
I have seen many articles on this, and none are working for me. I have this code -
$var1->{reference} = sql_get_rows();
sub sql_get_rows(){
etc
return ($sth->fetchall_arrayref());
};
What I want to do is know how many rows are found…

Geo1986
- 65
- 1
- 2
- 8
0
votes
2 answers
Perl- Dereferencing an arrayref and assigning the result to a variable results in variable having the value 1
I am trying to parse a log line which comes in to my script as an array reference.
I have another subroutine to which this log line is passed to extract a certain value, however the function does not seem to receive the log line and instead gets the…

sudologin
- 91
- 1
- 7
-1
votes
1 answer
Perl: sort hash ref using multiple array ref values
I have a hash ref with values being an array ref. I would like to sort the hash using multiple values. For example:
{ 'ID' => ['Age', 'Name', 'Start-Date'] }
I would like to sort by: 1) Age; then-by by 2) Start-Date (if Ages are equal). For…

h q
- 1,168
- 2
- 10
- 23
-1
votes
1 answer
Array ref empty when received by a sub
I am trying to access elements of arrays by reference, passing references into a sub. Here is my code snippet:
my @arr1 = (1,2);
my @arr2 = (3,4);
my @arr3;
push @arr3, \@arr1;
push @arr3, \@arr2;
for my $i (@arr3) {
print "$i\n";
}
print…

postoronnim
- 486
- 2
- 10
- 20
-1
votes
1 answer
How to calculate number of rows of a referenced array in Perl
A part of my code calculates inverse of a matrix (generated previously in the code) with dimensions more than 300 X 300. I want to use the elements of the inversed matrix further in the code. Have used the below code for this, trying with only 5X5…

moherangde
- 3
- 1
-1
votes
3 answers
how to declare array reference in hash refrence
my $memType = [];
my $portOp = [];
my $fo = "aster.out.DRAMA.READ.gz";
if($fo =~/aster.out\.(.*)\.(.*)\.gz/){
push (@{$memType},$1);
push (@{$portOp},$2);
}
print Dumper @{$memType};
foreach my $mem (keys…

Rahul Reddy
- 12,613
- 10
- 22
- 21
-2
votes
1 answer
Perl dynamic hash traversal
A hash of (0 or more levels of hash refs of) array refs of hash refs. Note that the level above the leaf nodes will always be array refs, even if they only have one element.
I need to fetch the aggregate sum of VALUE (in an array of array ref) by…

Aman Vidura
- 85
- 2
- 10