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

Perl how to access a value of nested hash without specific some middle keys (wildcard)

I trying to fetch the facebook mobile posts. $VAR1 = { "mf_story_key" => "225164133113094", "page_id" => "102820022014173", "page_insights" => { "102820022014173" => { "actor_id" => "102820022014173", …
Boontawee Home
  • 935
  • 7
  • 15
1
vote
1 answer

Hashref assignment consumes next key instead of assigning undef

I'm trying to initialize a hashref containing the results of several expressions. I would expect expressions that return undefined results to assign undef to the appropriate key. Instead, the assignment just gobbles up the next key as though the…
plentyofcoffee
  • 478
  • 2
  • 11
1
vote
0 answers

Perl DBI: Insert a whole hash in a single call, complement to fetchall_hashref()

I am using Perl DBI with DBD::Informix but I suspect the exact database is not important to this question. Bottom line: I'm looking for a mass-insert method where I can insert the contents of a hash [of hashes] into a table in one…
Jacob Salomon
  • 161
  • 1
  • 4
1
vote
1 answer

Perl - Issue getting array values from array stored in a hash reference

So I am currently working on a perl project where I need to pass an array (containing Id's to reject) stored as a hash reference, to another sub where I access the array use its contents in a json file I am creating. I currently wish to have the…
George c
  • 65
  • 1
  • 9
1
vote
1 answer

Perl fetchrow_hashref results are different integer vs. string values

I really need your help for understanding with the following perl example code: #!/usr/bin/perl # Hashtest use strict; use DBI; use DBIx::Log4perl; use Data::Dumper; use utf8; if (my $dbh =…
Arties
  • 190
  • 4
  • 11
1
vote
1 answer

Perl hash reference as argument to subroutine - Can't use string as a HASH ref

I was trying to prepare a small script with hash and subroutine. Honestly Iam a newbie in perl. Can someone tell me whats wrong with the below code. Im getting Can't use string ("1") as a HASH ref error. #!/usr/bin/perl use strict; use warnings; no…
Arun Kumar
  • 45
  • 7
1
vote
4 answers

HTML in AngularJS

I have an issue with the in my AngularJS app. My main issue is on the: navigation.html -> this is a template of navigation directive.
Marksmanship
  • 169
  • 1
  • 11
1
vote
1 answer

Save json string to mongodb in perl efficiently (without converting to hash-ref)

I would like to insert data to mongodb in perl. I can insert perl objects like hash-ref. But I want to append to them also prepared JSONs. I have these JSONs in text files and I can transform them to hash-ref and then put to database but I looking…
Daniel
  • 7,684
  • 7
  • 52
  • 76
1
vote
1 answer

Perl Array index to Hash value

I'm new to Perl and I want to turn this: $a = ["apple", "orange", "banana"]; Into this: $b = { "apple" => 0, "orange" => 1, "banana" => 2 }; Is there an elegant way of doing this instead of iterating and assigning a counter manually?
Can
  • 377
  • 2
  • 10
1
vote
1 answer

How to loop access hashref?

I have some data in a hashref format. I fetch the data from graph.facebook.com. How can I access the data in the hash with a loop? $var = \{ 'data' => [ { 'id' =>…
Boontawee Home
  • 935
  • 7
  • 15
1
vote
2 answers

How can I stop or allow a perl object to be used as a hashref?

I have a Perl class which is a based on a blessed hashref ( https://github.com/kylemhall/Koha/blob/master/Koha/Object.pm ) This is a community based project, with many developers of varying skill. What I've seen is some developers accidentally using…
Kyle
  • 213
  • 1
  • 3
  • 13
1
vote
1 answer

Create secondary hashtables for fast search of values

I have a hashref of the following format: { introduction_to_systems => { writer => "John", owner => "Jim" }, management_recipies => { …
Jim
  • 18,826
  • 34
  • 135
  • 254
1
vote
2 answers

Perl Hash reference is changing in threads

I am using perl with threads to process socket info ConnectionThread is responsible for receiving packets and parsing, and enque in a hash QueueThread Is responsible for processing Queue elelemts (hash entries ) and update DB The Hash is Events and…
1
vote
2 answers

Accessing args in Perl Hash Ref

$self->doSomething({ record => $record, listing => [ $foo, $bar, $baz ], passedargs => { something => $val, another => $val2 } }); accessing args within a hashref. So if I wanted to access record I would my $record =…
1
vote
1 answer

Perl args and defining it

Hello I am trying to understand Perl better. I come from Ruby and trying to wrap my head around Perl for fun. Let's say I have this code block here. $self->doSomething( { record => $record, listing => [ $foo, $bar, $baz ], …