Questions tagged [perl-data-structures]

Discussion of Perl's three built-in data types: scalars, arrays of scalars, and associative arrays of scalars, known as "hashes". At your command-line: perldoc perldata

perldata - Perl data types

perldsc - Perl Data Structures Cookbook

388 questions
8
votes
2 answers

Search for hash in an array by value

I have a function which extracts Excel data into an array of hashes like so: sub set_exceldata { my $excel_file_or = '.\Excel\ORDERS.csv'; if (-e $excel_file_or) { open (EXCEL_OR, $excel_file_or) || die("\n can't open…
DidYouJustDoThat
8
votes
5 answers

Dynamically/recursively building hashes in Perl?

I'm quite new to Perl and I'm trying to build a hash recursively and getting nowhere. I tried searching for tutorials to dynamically build hashes, but all I could find were introductory articles about hashes. I would be grateful if you point me…
Gaurav Dadhania
  • 5,167
  • 8
  • 42
  • 61
8
votes
6 answers

How do I create a hash of hashes in Perl?

Based on my current understanding of hashes in Perl, I would expect this code to print "hello world." It instead prints nothing. %a=(); %b=(); $b{str} = "hello"; $a{1}=%b; $b=(); $b{str} = "world"; $a{2}=%b; print "$a{1}{str} $a{2}{str}"; I…
Mike
  • 58,961
  • 76
  • 175
  • 221
7
votes
4 answers

Create combinations from elements in an array

I have an array reference like below: my $strings = [qw(a b c d)]; I want to form all possible combination and create an array of array as: my $output = [qw(qw([a],[b],[c],[d],[a,b],[a,c],[a,d],[b,c],[b,d],[c,d], …
questionar
  • 274
  • 2
  • 18
7
votes
1 answer

use of perl's eq operator changes type of the arguments

I made this script to check how scalars change when accidently using 'eq' instead of '==' and vice versa. Using '==' on strings changes nothing but using 'eq' on numbers makes the scalar change somehow. Here comes the code: #!/usr/bin/perl use…
7
votes
3 answers

Convert string "a.b.c" to $hash->{a}->{b}->{c} in Perl

I've dynamic nested hash-refs like this: my $hash = { 'a' => { 'b' => { 'c' => 'value' } } }; I want to set the value of c to 'something' by allowing the user to input "a.b.c something". Now getting the value could be done like this: my $keys =…
agranig
  • 129
  • 1
  • 7
6
votes
3 answers

Perl multi-dimensional table with headers

I'm trying to implement a multi-dimensional table with headers. Here's an example for 2D: < dimension1 > /\ 'column0' 'column1' dimension0 'row0' data00 data10 \/ 'row1' data01 …
Giovanni Funchal
  • 8,934
  • 13
  • 61
  • 110
6
votes
1 answer

What kind of data format is this?

I have a bunch of data files of the following form: ("String" :tag1 (value) :tag2 (value2) :tag3 ( :nested_tag1 (foo) :nested_tag2 ( :nested2_tag1 ( : ( nested3_tag1 …
wawawawa
  • 431
  • 3
  • 12
6
votes
2 answers

Can references be made without declaring a variable first?

I have this code that works my @new = keys %h1; my @old = keys %h2; function(\@new, \@old); but can it be done without having to declare variables first? function must have its arguments as references.
Sandra Schlichting
  • 25,050
  • 33
  • 110
  • 162
6
votes
1 answer

Including Hashes within Hashes in Perl

G'Day, I'm currently working on creating big hashes from a lot of smaller hashes. Let's say that these smaller hashes are defined in a file each, and then can be included by the bigger hash. For eg, let's look at some small hashes File…
Gaurav Dadhania
  • 5,167
  • 8
  • 42
  • 61
6
votes
7 answers

How can I merge several hashes into one hash in Perl?

In Perl, how do I get this: $VAR1 = { '999' => { '998' => [ '908', '906', '0', '998', '907' ] } }; $VAR1 = { '999' => { '991' => [ '913', '920', '918', '998', '916', '919', '917', '915', '912', '914' ] } }; $VAR1 = { '999' => { '996' => [] } };…
Nick
  • 191
  • 1
  • 9
6
votes
4 answers

How can I create a nested hash as a constant in Perl?

I want to do, in Perl, the equivalent of the following Ruby code: class Foo MY_CONST = { 'foo' => 'bar', 'baz' => { 'innerbar' => 'bleh' }, } def some_method a = MY_CONST[ 'foo' ] end end # In some other file which…
Pistos
  • 23,070
  • 14
  • 64
  • 77
6
votes
2 answers

Perl serializing and Deserializing hash of hashes

I am trying to serialize a hash of hashes and then deserializing it to get back the original hash of hashes ..the issue is whenever i deserialize it ..it appends an autogenerated $var1 eg. original hash %hash=(flintstones => { husband =>…
user1547285
  • 63
  • 1
  • 3
6
votes
4 answers

Adding value to array if condition is fulfilled

I am building an array of hashes of arrays my @array = ( {label => 'first hash'}, {label => 'second hash', innerarray => [ {label => 'first inner hash'}, {label => 'second inner hash'}, ] }, ); Is there a way…
Pit
  • 1,448
  • 1
  • 18
  • 26
5
votes
2 answers

How do I process a partial order of tasks concurrently using Perl?

I have a partially ordered set of tasks, where for each task all of the tasks that are strictly before it in the partial order must be executed before it can be executed. I want to execute tasks which are not related (either before or after one…
lexicalscope
  • 7,158
  • 6
  • 37
  • 57
1
2
3
25 26