Questions tagged [hashref]

Use this tag for questions related to a hashref, an abbreviation to a reference to a hash.

Quoting this answer:

A hash is a basic data type in Perl. It uses keys to access its contents. A is an abbreviation to a reference to a hash. References are scalars, that is simple values. It is a scalar value that contains essentially, a pointer to the actual hash itself.

Make sure to use as well in your question.

82 questions
0
votes
1 answer

Perl / DBI query doesn't preserve integer values for JSON output

I can't get this Perl code to return true integer values for integers in the table. The MySQL table columns are correctly specified as integers, yet the JSON output here wraps all query values in quotes. How can I correctly preserve data-types (esp.…
Colin R. Turner
  • 1,323
  • 15
  • 24
0
votes
2 answers

Merging N no of files based on their first column in perl

My question is similar to this question posted earlier. I am having many files which I need to merge them based on the presence or absence of the first column ID, but while merging I am getting lots of empty values in my output file, I want those…
Kanhu
  • 39
  • 5
0
votes
3 answers

Perl - Create Array of Hashes based on Hash filter

I have this hash that contains some information: my %hash = ( key_1 => { year => 2000, month => 02, }, key_2 => { year => 2000, month => 02, }, key_3 => { year => 2000, month =>…
rnarcos
  • 86
  • 1
  • 2
  • 12
0
votes
3 answers

How can I reference a hash using a variable name?

I have a set of pre-defined hash tables and I want to reference one of those hashes using a variable name and access a key value. The following code just returns null even though the hash is populated. What am I doing wrong here, or is there a…
Colin R. Turner
  • 1,323
  • 15
  • 24
0
votes
1 answer

Can't use an undefined value as a HASH reference - Perl Mojolicious

So I'm a bit of a noob at Perl but in essence this code is part of my model (inserting into an SQL database). The error I'm getting when running this code is Can't use an undefined value as a HASH reference I think the clear solution to this is to…
dipl0
  • 1,017
  • 2
  • 13
  • 36
0
votes
0 answers

a href with # not working on mobile, only desktop

I created a shortcode on Wordpress to display a button the html output is About Page However when I put /#solutions in the href tag Explore Our Solutions it…
Ken Ryan
  • 539
  • 1
  • 10
  • 31
0
votes
2 answers

perl hashref lookup function always returning default value

I have the following function which SHOULD return true or false when I look up a key and value in a hashref. I am sure I am missing something but what ? The function shoudl return true or false if the key value strings that we search for are…
Mike Rossi
  • 25
  • 4
0
votes
1 answer

Can't use string ("6/16") as a HASH ref while "strict refs" in use

I have a script which has code something like below. $shelf->print("\nStarted syncing from \"${%Family::MEMBERS}{$member}\" \n"); When I attempt to run it locally on CentOS 7.0 with perl(v5.8.8) it works fine, however the same code on same OS with…
MangeshBiradar
  • 3,820
  • 1
  • 23
  • 41
0
votes
3 answers

Access Data Dumper nested Perl Hash

I have a Perl hash reference $artifact that I am printing using Data::Dumper. The output of print Dumper ($artifact); returns the following. $VAR1 = bless( { '_content' => '{ "results" : [ { "uri" : "http://localhost:port/myfile.tar" …
user2402135
  • 371
  • 1
  • 6
  • 19
0
votes
2 answers

Perl: Returning hashref from subroutine

I have a hash that is a deeply nested structure. The level of nesting is not known before-hand. But each level has two properties "instance" and another hash of "dependencies". So it's a kind of recursive-looking hash. my $HASH = { "top"=> { …
shikhanshu
  • 1,466
  • 2
  • 16
  • 32
0
votes
1 answer

How to parse complicated hash ref in perl?

I used JSON::Parse to decode a json file. When I dumped it to a file it looks as printed below. I need to extract the 'url' from each of the repositories. How can I go about doing that? I have tried to access the elements, but cannot seem to get…
Busch
  • 857
  • 10
  • 29
0
votes
2 answers

get all nodes from multi level hash in perl

I want all nodes of each key sorted by key in hash ref or array or something like so that I can iterate that according to my need since I have to display each key with its all children. following is my data structure: $hash1 = { '3' => {…
0
votes
2 answers

Perl - Hash reference structure of variable depth

I have a question I am hoping someone could help with. I have a tab-delimited text file called FILE.txt: (note two of the ages are missing): BOY Fred Smith 56 BOY David Jones 18 GIRL Anne Roberts BOY Fred …
yonetpkbji
  • 1,019
  • 2
  • 21
  • 35
0
votes
2 answers

hashref check using if condition returns null

Been using perl for a while but quite often encounter this, Say, $results is a hashref and code is like below: $results->{'Key_1'} = 'Valid_string'; if ( $results->{'Key_1'} ) { ---> this doesn't return true Code to do something ..... } If my…
NullException
  • 4,232
  • 8
  • 24
  • 44
0
votes
1 answer

Perl hashref/property confusion

Ignoring the fact that this probably wouldn't happen if one was using strict and warnings, I'd like to know why these two cases differ. #!/usr/local/perl5/bin/perl $x[0] = ""; $y[0] = ""; $x[0]->{name} = "SRV"; $y[0]->{name} = "FINAL"; print…
Sean
  • 431
  • 2
  • 6
  • 14