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
1
vote
2 answers

How can I update a hash value using a hash reference in Perl?

Is there a way to update a value in a hash using a hash reference that points to the hash value? My hash output looks like this: 'Alternate' => { 'free' => '27.52', 'primary' => 'false', 'used' => '0.01', 'name'…
user2063351
  • 503
  • 2
  • 13
  • 31
1
vote
2 answers

DBI::st=HASH()->_prepare(...): attribute parameter is not a hash - Perl

I begginer in Perl and I've got this problem: my $query = qq {select a1, count(b2), c3 from tab where d1 = ? group by a1, c3 }; my $res = $dbh->selectall_hashref( $query,{ Slice => {} }, $id->[0]); When execute the code, I…
jAbreu
  • 307
  • 2
  • 10
1
vote
1 answer

can't get hash value from hashref

I'm storing a hash references from a threads to a shared @stories variable, and then can't access them. my @stories : shared= (); sub blah { my %stories : shared=(); if ($type=~/comment/) { …
1
vote
2 answers

Unless constructor argument passed is a hash type, croak on invalid arguments?

I am vaguely confused a bit on different methods of passing certain arguments to the constructor type. I want to only pass a hash reference \%hash, or a list foo => 1, bar => 1 but not both and croak if anything else is passed i.e ( single elements,…
hwnd
  • 69,796
  • 4
  • 95
  • 132
1
vote
1 answer

Get all data from DB using fetchall_hashref

I am using fetchall_hashref to get data satisfying a condition from a mysql DB.The data retrieved will be stored in a hash and then be used futhur by a javascript function. I want to retrieve all the rows of 3 columns and store it in a hash but not…
Lucy
  • 1,812
  • 15
  • 55
  • 93
1
vote
2 answers

How to build a hashref with arrays in perl?

I am having trouble building what i think is a hashref (href) in perl with XML::Simple. I am new to this so not sure how to go about it and i cant find much to build this href with arrays. All the examples i have found are for normal href. The code…
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…
1
vote
1 answer

Validation Failing for Valid Hashref

I'm deploying my software (first time in a new environment) and hitting a wall almost immediately. I have a value that is failing its HashRef validation, but every test I can think of makes it seem like it should be valid. Attribute (store) does…
Ryan
  • 672
  • 1
  • 6
  • 16
1
vote
3 answers

Perl loop thru nested blessed hashref elements

I have a perl data structure similar to the following: $VAR1 = bless( { 'admin' => '0', 'groups_list' => [ bless( { …
Drek
  • 87
  • 1
  • 10
1
vote
2 answers

Perl: What's the proper way to pass a hash ref plus additional keys/values as one hash ref?

The purpose is to only ammend the hashref argument being passed to the function, but not modify the original hashref. { my $hr = { foo => q{bunnyfoofoo}, bar => q{barbiebarbar} }; foo( { %$hr, baz => q{bazkethound} }…
vol7ron
  • 40,809
  • 21
  • 119
  • 172
0
votes
1 answer

How can I use "map" in "perl" to return a hash reference whose key is looked up from an array reference whose value is looked up from another array?

I've searched other many Stack questions on map however this requirement is particular and well try as I might I cannot quite get the solution I am looking for, or I think that does exist. This question is simply about performance. As limited,…
Mark Arnold
  • 253
  • 3
  • 9
0
votes
2 answers

How to pop from an array inside a hashref?

Brain getting foggy on this one. I wanted to take my dice game from using rand() to using a list of random values from random.org. I was able to retrieve the values just fine, I'm just hung up on the syntax to pop from the list. Here's my function…
coding_hero
  • 1,759
  • 3
  • 19
  • 34
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

Extracting values from hash created by perl JSON::Syck::Load

I've got a very simple Perl issue that I can't for the life of me figure out. I'm consuming JSON formatted data from a REST endpoint in a perl script. The data is shaped like this: { "ScriptRunning": true } There's some other stuff, but really…
redsoxfantom
  • 918
  • 1
  • 14
  • 29
0
votes
2 answers

How to fix the classic anchor method (id-href) in Angular?

On the homepage component I use scrolling in order to show the different divs of the page. The div looks loke this:
Paragraph1
Paragraph2
Paragraph3
On the same page I…
user11903678