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
-2
votes
2 answers

How do i store file contents for first 10 second in perl

hello all i have a file xyz.txt having following info 69013 1-3039-1 REGISTER 69013 1-3039-1 100 69013 1-3039-1 401 69013 1-3039-2 REGISTER 69013 1-3039-2 100 69013 2-3039-1 REGISTER 69013 3-3039-1 REGISTER 69013 4-3039-1…
singhabsk
  • 31
  • 3
-2
votes
2 answers

@How to convert strings to integers on a split in Perl

I am reading in lines from a data file one at a time, splitting them on : and trying to store two specific values from the array into a hash. foreach $a () { @list = split (':', $a); $UIDH{$list[2]} = $list[5]; Then I try to…
Ark Angel
  • 61
  • 1
  • 3
  • 12
-2
votes
1 answer

How to stop array sort in Perl

I knew this is a very basic question in Perl so i could not find solution for this anywhere. I am using Perl package Text::ASCIITable to beautify the output. Below is my code, where i am constructing table row using array. my @output = [ { …
Raja
  • 3,477
  • 12
  • 47
  • 89
-2
votes
3 answers

Read a CSV file with uneven commas but fixed number of columns

I want to able to read this CSV file into an array of arrays or hashes for manipulation. How can I go about it? For example my file contains the following (the first line is the…
Kiluvya.a
  • 15
  • 4
-2
votes
2 answers

Sorting in perl in a particular way

I am writing a program in Perl. A part of it requires sorting of numbers. But it's not a normal sorting. The values are something like this. 01,02,03,04,05,97,98,99. I want it to be sorted like this. 97 98 99 01 02 03 04 05 We are sorting data…
nithin
  • 73
  • 2
  • 7
-2
votes
3 answers

Alphanumeric or natural sorting of keys in a hash

I have keys in a hash as follows: AB3, AB1, AB2 and so on. I would like to sort the hash by the keys. How do I do this in perl? A related issue is how can I sort the keys so that letters and numbers appear in the correct order?
-2
votes
1 answer

perl nested regex

Text record: (1,2,3,4,{fred,don,max,rat,grp},45,67,mat,jhon,{a,b,1,2,sd[{1,2},{4,5}],45,67,P[{34,56,34},{uni,cast,r}],c{q,ew,3,4},1,2,3,cf{2,4,5,8},6},4,fr{24,45,67},5,NOL) Desired…
yuvi
  • 21
  • 3
-2
votes
4 answers

Perl script to read a directory and having file name started by a particular name

I have a directory containing thousand of file. Suppose I have 3 pdf files having same name like: sample_Q1.pdf sample_Q2.pdf sample_Q3.pdf Now I want to find the file list having particular name started with "Sample". I'm currently…
-2
votes
1 answer

How do i search and extract commented lines from a file using perl?

I am new to Perl programming. Need your help in searching and extracting only commented lines from a file. Below is an example { This is line 1 /*This is line 2 This is line 3 This is line 4*/ This is line 5 } I just want to…
sravan
  • 1
  • 2
-2
votes
1 answer

Array of hashes manipulation

I'm running the script below to query a monitoring system and the results I get back are in array of hashes. What is the best way to access the individual hashes and their elements? use strict; use warnings; use YMS::Client::MonStatus; use…
Ani
  • 109
  • 2
  • 12
-2
votes
4 answers

How can I sort a Perl array of array of hashes?

@aoaoh; $aoaoh[0][0]{21} = 31; $aoaoh[0][0]{22} = 31; $aoaoh[0][0]{23} = 17; for $k (0 .. $#aoaoh) { for $i(0.. $#aoaoh) { for $val (keys %{$aoaoh[$i][$k]}) { print "$val=$aoaoh[$i][$k]{$val}\n"; } } } The…
ksskr
  • 238
  • 4
  • 15
-2
votes
1 answer

objects(such as person) and items (such salary items) data design structure

This may be a classical requirement. Two key concepts objects and items, a time-change demand, the items can changed very quickly. Such as a person have so many salary items, and these items will be added and changed or deleted. Our solution is so…
Thai Heng
  • 152
  • 1
  • 11
-2
votes
1 answer

sort by two columns using sort and map in Perl

I have the list as @emprecords = ( ['pavan',24,25000], ['kumar',25,35000], ['ajay',22,35000], ['vijay',25,20000] ); i need to sort them by lowest age first with highest slary…
pavan
  • 334
  • 6
  • 20
-3
votes
5 answers

What's the best practise for Perl hashes with array values?

What is the best practise to solve this? if (... ) { push (@{$hash{'key'}}, @array ) ; } else { $hash{'key'} =""; } Is that bad practise for storing one element is array or one is just double quote in hash?
Tree
  • 9,532
  • 24
  • 64
  • 83
-3
votes
1 answer

How to set start and end boundary in perl

This is my code use strict; use warnings; my $string=" The UNIX grep filters the lines of a file based on a regular expression.Perl's grep can filter any list of value based on any condition. This Perl code implements a basic version of the…
Chella
  • 43
  • 6
1 2 3
25
26