Questions tagged [arrayref]
25 questions
13
votes
3 answers
Perl Inline C: Passing Arrayref to C Function
I can't get arrayrefs passed into a C function using Inline C. I would like some help, please.
First, just to prove I can get Inline C to work, I'll pass a scalar value to a C function:
#!/usr/bin/perl -I.
#
# try1.pl
#
use Inline C;
my $c =…

AndyFroncioni
- 181
- 1
- 8
7
votes
1 answer
perl Join with array reference
I am new to perl.
I am trying to use join with a array reference, but it is not working.
Here is my code.
my $arr = {
'items' => ('home', 'chair', 'table')
};
my $output = join(',', $arr->{'items'});
print $output;
It is printing…

Keen Sage
- 1,899
- 5
- 26
- 44
7
votes
2 answers
Shallow copy reference into variable in Perl
In Perl, you can assign to a variable a reference to another variable, like this:
my @array = (1..10);
my $ref = \@array;
And, as it is a reference, you can do something like this and both variables will be affected:
push @array, 11;
push @$ref,…

Francisco Zarabozo
- 3,676
- 2
- 28
- 54
6
votes
2 answers
Type of argument to keys on reference must be unblessed hashref or arrayref
if((scalar keys ($this->{'libraries'}->{$y}->{'cellHash'})) == 0){
This is the line where I am getting the "Type of argument to keys on reference must be unblessed hashref or arrayref" error. Can you help me fix this?
I am not posting the code…

Rahul Reddy
- 12,613
- 10
- 22
- 21
3
votes
4 answers
Perl: Create hash of hashes, last key as a reference to an array
http://codepad.org/8fJG5XaB
Need a little help creating hashrefs of hashrefs, with the last key as a reference to an array.
use Data::Dumper;
my $foo = "a:b:c:d:a";
my $bar = "a:b:c:d:z";
my $hoh = {};
sub createHash {
my…

vol7ron
- 40,809
- 21
- 119
- 172
3
votes
5 answers
How do I convert an array or a list into a hashref?
I have a list like this:
my $myV3VersionOfData = ["ZG","ZB","CXLDN",...];
and I want to convert it into a dictionary like this:
my $entries = {
'ZG' => {
'value' => 'ZG'
},
'ZB' => {
'value' => 'ZB'
},
'CXLDN' => {
'value' => 'CXLDN'
},
...
};
I…

raxchi
- 43
- 8
2
votes
1 answer
Creating container class in Perl (using Moose)
I'm trying to create a container class in Perl called Gene, which will store objects created by another class 'Cis' (so for example Gene1 will store Cis1a Cis1b Cis1c, and Gene2 will store Cis2a Cis2b Cis2c). This is what I have so far:
package…

Lisa
- 331
- 1
- 9
- 15
2
votes
1 answer
Appropriate way to return an arrayref from a sub with optional sorting in Perl version 5.20
I try to write a subroutine under Perl 5 version 5.20, that creates a large directory list stored in an array. The subroutine returns the result as an arrayref. For convenience reasons I want the have the option to sort the result.
#!/usr/bin/env…

huckfinn
- 644
- 6
- 23
2
votes
3 answers
perl sort multiple arryrefs of date time strings
I want to sort an arrayref %results (Time-strings, from old to new), it has multiple keys but I just posted one key to show how it looks like:
'Ende Monatswechsel P-Konten' => [
'17.02.2018 05:17:39',
…

Unsal
- 81
- 5
2
votes
2 answers
Perl selectall_array - retrieve all data from array of array ref
I am using DBI selectall_array to fetch all the data out of mysql. My query returns 1 columns for every row. But the selectall_array function returns an array of array ref for each row as listed below
$VAR1 = [
'1.ptmp'
];
$VAR2 =…

Rizwan Qureshi
- 23
- 1
- 5
2
votes
1 answer
Dynamically create hash of hash with array ref values
I want to dynamically create a structure as follows:
{
edition1 => {
Jim => ["title1", "title2"],
John => ["title3", "title4"],
},
edition2 => {
Jim => ["titleX",], …

Jim
- 18,826
- 34
- 135
- 254
2
votes
1 answer
Type of argument to keys on reference must be unblessed
I am very new to perl and I have been given the task of maintaining a webpage. I have found a bug that I do not know how to fix.
The perl script stops on the following code.
my @failedTests = (sort(keys…

AlexN
- 45
- 1
- 5
1
vote
1 answer
Perl dbi (select) fetches empy strings in array
I have a perl script that connect to a postgres db and fetches a couple select statements that it runs on it. This output have the purpose to print in word afterword. While i was building my project i didn't notice something that happens with the…

achahbar
- 901
- 3
- 21
- 47
1
vote
2 answers
Joining an array of arrays
I have an array @ary of unknown size. Each element, $ary[$i], is an arrayref of unknown size. Each element of that, $ary[$i][$j], is a string.
I wish to concatenate all of the $ary[0][$j] with all of the $ary[1][$j] with all of the… and so on.
That…

JQKP
- 75
- 11
1
vote
2 answers
Elements of array ref used in multiple hashes not shown
In the following code when the contents of array are printed key3 of hashref2 does not have the desired values (What I wan to achieve is hashref1 to have an array in key3 with value1 and hashref2 to have an array in key3 with value2).
In the code…

Evangelos Valtos
- 65
- 4