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
0
votes
1 answer

Perl: How to make an optimal ranking

My brother has thousands of items ids and the number of items sold in the following fashion: $VAR1 = { 'sold_times' => 4, 'item_id' => 1, }; $VAR2 = { 'sold_times' => 1, …
ado
  • 1,451
  • 3
  • 17
  • 27
0
votes
4 answers

How do I create and add anonymous hashes to a known Hash during script execution?

I'll attempt to illustrate this with an example. Take a common example of a Hash of Hashes: my %HoH = ( flintstones => { lead => "fred", pal => "barney", }, jetsons => { lead => "george", wife …
Mick
  • 13,248
  • 9
  • 69
  • 119
0
votes
1 answer

Perl XML::SAX - character() method error

I'm new to using Perl XML::SAX and I encountered a problem with the characters event that is triggered. I'm trying to parse a very large XML file using perl. My goal is to get the content of each tag (I do not know the tag names - given any xml…
GPN
  • 1
0
votes
2 answers

perl fileparse and push into multiple arrays

I have an array that contains file paths. I would like to split the array to give me the file_name, dir_name and the extension. I am trying to use File::Basename perl module. Can someone help me achieve this: foreach (@files) { …
soothsayer
  • 333
  • 2
  • 6
  • 14
0
votes
1 answer

reading textfile and saving theinfo into and array of array in perl

I have a text file which contains following code. I want create perl code to read that containt and form a corresponding data structure in perl. I can read the .txt file with below perl code but how to read and save that all in perl data structur…
ravikiran
  • 105
  • 1
  • 1
  • 7
0
votes
5 answers

How do I access arrays of array in perl?

Hi I have a array as myarray. I would like to make a list as '1 2 3' which is joining the first subarray. My string is printing the memory location I suppose instead of list. any help will be appreciated. @myarray = [[1,2,3],[4,5,6],[7,8,9]]; for…
0
votes
3 answers

Parsing JSON Data::Dumper output array in Perl

I'm trying to edit an old perl script and I'm a complete beginner. The request from the server returns as: $VAR1 = [ { 'keywords' => [ 'bare knuckle boxing', 'support…
user1882536
  • 13
  • 1
  • 5
0
votes
2 answers

Hash value is not re-initialized when loop is terminated with 'last' keyword

Consider the following nested loops: my %deleted_documents_names = map { $_ => 1 } $self->{MANUAL}->get_deleted_documents(); while($sth->fetch){ ..... ..... ..... while(my ($key, $value) = each(%deleted_documents_names)){ …
Manoj Agarwal
  • 365
  • 2
  • 17
0
votes
1 answer

how can tree like data structure be implemented in this case

I have a file like this A 100 200 A 120 220 B 140 250 Another file is like this A 130 210 A 133 215 B 180 270 Then I have to compare each row from first file to each row of second file and find which rows have intersecting co-ordinates Output…
dissw.geek9
  • 245
  • 1
  • 6
  • 11
0
votes
6 answers

reading columns from Hash of Arrays

I'm new in perl and have a question concerning the use of hashes of arrays to retrieve specific columns. My code is the following: my %hash = ( name1 => ['A', 'A', 'B', 'A', 'A', 'B'], name2 => ['A', 'A', 'D', 'A', 'A', 'B'], …
PedroA
  • 1,803
  • 4
  • 27
  • 50
0
votes
1 answer

Why does function call as argument to the push cause 'Not an ARRAY reference' in Perl?

Would somebody be so pleasant to explain why does the next thing happen? Here is the code: #!/usr/bin/perl use v5.14; use warnings; my @arr = (1, 2, 3); sub func { return @arr; } push(&func(), 4); say @arr; When I try to run it, the output…
d.k
  • 4,234
  • 2
  • 26
  • 38
0
votes
1 answer

Printing a Table from a Perl Data Structure

I have a Perl data structure like the following: %hash = ( table_id => { column_1_header => [ column_value_1, column_value_2, column_value_3 ], …
indiguy
  • 505
  • 1
  • 9
  • 21
0
votes
4 answers

Populating a perl array of hashes with copies of a single hash

I have searched and searched and I can't get any of the code I've found to work. I'm sorry if this is repeating old ground, but I've now spent 2 days trying to get these 10 lines to work and I am at my wits' end with no hair left :-( I am running…
Stephan
  • 99
  • 1
  • 9
0
votes
2 answers

How To Convert a Hexadecimal String into Byte Array using Perl

I Would Like to convert an Hexadecimal String Say [0] =0x4A ,[1] =0x06 ,[2] =0x0E ,[3] =0xF1 ,[4] =0x95 ,[5] =0x3B ,[6] =0xD9 ,[7] =0x90 ,[8] =0x5B ,[9] =0x63 ,[10]=0xCA ,[11]=0xA9 ,[12]=0x37 ,[13]=0xC8 ,[14]=0x8D …
user285686
  • 195
  • 1
  • 2
  • 11
0
votes
4 answers

How do I access variable's value in perl where I have multiple variables with its value and ends with ;

I have a txt file like this $CHUNK_QTY = "50000"; $CLIENT = "hi all"; $CLIENT_CODE = "NMB"; $COMPOSER = "DIALOGUE"; $CONTROL_FILE_NAME = "NMBM725.XML"; $COPY_BASE = "01"; $CSITE = "NSH"; $DATA_TYPE = "MET"; $DIALOGUE_VERSION =…
mysteriousboy
  • 159
  • 1
  • 7
  • 20