perl-data-structures

Perl Merge file

最后都变了- 提交于 2019-12-19 10:25:14
问题 I have 3 or multiple files I need to merge, the data looks like this.. file 1 0334.45656 0334.45678 0335.67899 file 2 0334.89765 0335.12346 0335.56789 file 3 0334.12345 0335.45678 0335.98764 Expected output in file 4, 0334.89765 0334.89765 0334.89765 0334.12345 0335.67899 0335.12346 0335.56789 0335.45678 0335.98764 So far I have tried but data in 4rth file does not come in sorted order, #!/usr/bin/perl my %hash; my $outFile = "outFile.txt"; foreach $file(@ARGV) { print "$file\n"; open (IN, "

Sort by value hash of hash of hashes Perl

旧巷老猫 提交于 2019-12-18 13:38:32
问题 I have a hash structure similar to the following: KeyA => { Key1 => { Key4 => 4 Key5 => 9 Key6 => 10 } Key2 => { Key7 => 5 Key8 => 9 } } KeyB => { Key3 => { Key9 => 6 Key10 => 3 } } I need to print out the traversal path through the hash structure and the value at the end of the traversal, such that this is ordered by value. For example, for the above hash structure I need to print: KeyB Key3 Key10 3 KeyA Key1 Key4 4 KeyA Key2 Key7 5 KeyB Key3 Key9 6 KeyA Key2 Key8 9 KeyA Key1 Key5 9 KeyA

Generating sets of array in perl

╄→гoц情女王★ 提交于 2019-12-13 11:21:07
问题 Given perl script cut the input sequence at "E" and skips those particular positions of "E" which is mentioned in @nobreak, and generates an array of fragments as an output. But I want a script which generates set of such array in output for every position which has been skipped taking all positions of @nobreak into account. say set 1 contains fragments resulted after skipping at "E" 37, set 2 after skipping at "E" 45, and so on. Below mentioned script which I wrote is not working correctly.

Perl two column flat file to a complex unordered list tree

好久不见. 提交于 2019-12-13 05:08:04
问题 I have a data file for an organizational chart that has been pulled from our AD structure and looks like this, with the Manager being the first field, and the employee the second - in some situations a manager will look after a few staff: __EXAMPLE__ user4 user8 user8 user9 user1 user1 user2 user2 user3 user2 user5 user2 user4 user3 user5 user4 user6 user4 user7 This needs to be output in a HTML unordered list such as this: # Intended output # # <ul> # <li>user1</li> # <ul> # <li>user2</li> #

How can I sort Perl hashes whose values are array references?

a 夏天 提交于 2019-12-12 14:24:24
问题 Hey I was just wondering if there is a cool "one liner" that would sort my hash holding array references. So I have a bunch of key/values in my hash something like: $DataBase{$key} = \@value; However I would like to sort the hash by the array[0] element. Then loop through 'em. I had this to begin with: foreach my $key (sort {$DataBase{$a} cmp $DataBase{$b} } keys %DataBase) But that obviously just sorts my hash by the pointer value of the array. It doesn't exactly have to be "one line" but I

How to reference a hash of array of hashes in order to compare values

一世执手 提交于 2019-12-12 04:32:51
问题 I have the following data structure: my %hash = ( 'hsa_circ_0024017|chr11:93463035-93463135+|NM_033395|KIAA1731 FORWARD' => [ { 'energy' => '-4.3', 'spacer' => 'AGGCACC', 'end' => '97', 'start' => '81' } ], 'hsa_circ_0067224|chr3:128345575-128345675-|NM_002950|RPN1 FORWARD' => [ { 'energy' => '-4.4', 'spacer' => 'CAGT', 'end' => '17', 'start' => '6' }, { 'energy' => '-4.1', 'spacer' => 'GTT', 'end' => '51', 'start' => '26' }, { 'energy' => '-4.1', 'spacer' => 'TTG', 'end' => '53', 'start' =>

Use a Perl's Data::Dumper format array in PHP

对着背影说爱祢 提交于 2019-12-11 23:28:05
问题 I need to acces an array wich is outputed by Perl's Data::Dumper. Array is in a raw file, and I need to acces it with php. Array is formated as this: $stats = { 'days' => 25, 'lengths' => { 'Piwee' => 269, 'Jeanne-' => 904, 'kaAnar' => 340, [... Very Big ARRAY....] I found this solution on here, but i dont want to use eval() because this array will have user-input data. Since i will always need to eval() output in case of a str_replace solution, i think i need to find another way to do it.

Perl - Compare two nested hash

落花浮王杯 提交于 2019-12-11 02:17:30
问题 This is my scenario, where there are 2 hashes that have been decoded from 2 JSON files. I have 2 complex hash, $hash1 = {k1=> { k11 => v1, k12 => v2}, k2 => { k21 => [v1, v2, v3] }} $hash2 = {k1=> { k11 => v1, k12 => v2}, k2 => { k21 => [v3, v2, v1] }} I want to compare these 2 hash for equality, and used Compare of Data::Compare and is_deeply of Test::More. Both do not ignore the order of the array. I want to compare ignoring the order of array values of key 'k21'. My App populates the array

How to get the key associated with a hash reference's key in a hash of hashes?

≯℡__Kan透↙ 提交于 2019-12-11 01:11:49
问题 In an attempt to help me learn Perl, I built the following data structure, where the inner hash (/DriveA/archive, etc.) is a hash reference: #The contents of the %properties hash of hashes #The inner hash is a hash reference to a hash named %attributes $VAR1 = { '/DriveA' => { '/DriveA/archive/' => { 'MaxSize' => '20GB', 'Size' => '19GB', 'Free' => '5' }, '/DriveA/current/' => { 'MaxSize' => '20GB', 'Size' => '12GB', 'Free' => '40' } }, '/DriveB' => { '/DriveB/archive/' => { 'MaxSize' => '8GB

How do I access arrays of array in perl?

流过昼夜 提交于 2019-12-08 14:07:10
问题 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 (my $i=0; $i < @myarray; $i++) { my @firstarray = $myarray[$i]; my $mystring = join("", @firstarray); print "My string ".$mystring . ". "\n"; } 回答1: You have to dereference the inner array reference by @{ ... } . Also, do not use [...] for the top