perl-data-structures

Perl - How do I update (and access) an array stored in array stored in a hash?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-07 04:18:26
问题 Perhaps I have made this more complicated than I need it to be but I am currently trying to store an array that contains, among other things, an array inside a hash in Perl. i.e. hash -> array -> array use strict; my %DEVICE_INFORMATION = {}; #global hash sub someFunction() { my $key = 'name'; my @storage = (); #assume file was properly opened here for the foreach-loop foreach my $line (<DATA>) { if(conditional) { my @ports = (); $storage[0] = 'banana'; $storage[1] = \@ports; $storage[2] = '0

Perl encounters “out of memory” in openvms system

☆樱花仙子☆ 提交于 2020-01-06 06:53:15
问题 I am using a 32 bit perl in my openvms system.(So perl can access up till 2gb of virtual address space ). I am hitting "out of memory!" in a large perl script. I zeroed in on the location of variable causing this . However after my tests with devel:size it turns out the array is using only 13 Mb memory and the hash is using much less than that. My question is about memory profiling this perl script in VMS. is there a good way of doing memory profile on VMS? I used size to get size of array

Perl:Access values of hash inside a hash

試著忘記壹切 提交于 2020-01-02 09:59:31
问题 I have just picked up Perl. I have a little confusion with accessing hash values. Below is the code where I am trying to access the values of a hash inside a hash. Since am using a simple text editor to code, I am not able to figure out what can be the problem. Please help my %box = ( Milk => { A => 5, B => 10, C => 20, }, Chocolate => { AB => 10, BC => 25, CD => 40, }, ); foreach my $box_key(keys %box) { foreach my $inside_key (keys %box{box_key}) print "$box_key"."_$inside_key""is for

Search for hash in an array by value

旧街凉风 提交于 2020-01-01 10:06:14
问题 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 $excel_file_or: $!\n"); while () { chomp; my ( $id, $date, $product, $batchid, $address, $cost ) = split ","; my %a = ( id => $id , date => $date , product => $product , batchid => $batchid , address => $address , cost => $cost ); push ( @array_data_or, \%a ); } close EXCEL_OR;

Perl: Generating Arrays inside a Complex Hash

人盡茶涼 提交于 2019-12-30 12:16:10
问题 In the quest to make my data more accessible, I want to store my tabulated data in a complex hash. I am trying to grow a 'HoHoHoA' as the script loops over my data. As per the guidelines in 'perldsc': push @ { $hash{$column[$i]}{$date}{$hour} }, $data[$i]; The script compiles and runs without a problem, but doesn't not add any data to the hash: print $hash{"Frequency Min"}{"09/07/08"}{"15"}; returns nothing even though the keys should exist. Running an 'exists' on the hash shows that it does

Perl: Generating Arrays inside a Complex Hash

孤者浪人 提交于 2019-12-30 12:16:02
问题 In the quest to make my data more accessible, I want to store my tabulated data in a complex hash. I am trying to grow a 'HoHoHoA' as the script loops over my data. As per the guidelines in 'perldsc': push @ { $hash{$column[$i]}{$date}{$hour} }, $data[$i]; The script compiles and runs without a problem, but doesn't not add any data to the hash: print $hash{"Frequency Min"}{"09/07/08"}{"15"}; returns nothing even though the keys should exist. Running an 'exists' on the hash shows that it does

How does double arrow (=>) operator work in Perl?

大城市里の小女人 提交于 2019-12-28 02:07:06
问题 I know about the hash use of the => operator, like this $ cat array.pl %ages = ('Martin' => 28, 'Sharon' => 35, 'Rikke' => 29,); print "Rikke is $ages{Rikke} years old\n"; $ perl array.pl Rikke is 29 years old $ and I thought it was just syntax to initialize hashes, but in answers to How can I qualify a variable as const/final in Perl?, => has been used like this use Readonly; Readonly my $infilename => "input_56_12.txt"; What exactly does => mean? Are there more ways in which => can be used?

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

断了今生、忘了曾经 提交于 2019-12-23 10:08:06
问题 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' => [] } }; $VAR1 = { '999' => { '995' => [] } }; $VAR1 = { '999' => { '994' => [] } }; $VAR1 = { '999' => { '993' => [] } }; $VAR1 = { '999' => { '997' => [ '986', '987', '990', '984', '989', '988' ] } }; $VAR1 = { '995' => { '101' => [] } }; $VAR1 = { '995' => {

Perl Array References and avoiding “Type of arg 1 to keys must be hash” error

帅比萌擦擦* 提交于 2019-12-23 07:57:36
问题 I have a scalar $subscribers that could be undef, reference to a HASH, or reference to an ARRAY. I have assigned the sample values $VAR1 , $VAR2 and $VAR3 for testing. I'm only interested in $subscribers when it is a reference to an ARRAY, where by it would contain multiple values. In other cases, I'm not interested in printing anything (e.g. when $subscribers=$VAR2; The code seems to run fine under Perl v5.16.2; however, when I move it to the target machine running Perl v5.8.8, I get a

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

冷暖自知 提交于 2019-12-22 05:06:55
问题 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 = 'a.b.c'; my $v='something'; my $h = $hash; foreach my $k(split /\./, $keys) { $h = $h->{$k}; } print $h; # "value" But how would I set the value of key c to $v so that print Dumper $hash; would reflect the change? $h is not a ref at the end of the