My intention is to create a Hash of Array. The arrays should contain columnwise substring of length (in this case) 2 from each lines (all line is of same length). Furthermore, the keys should contain the position (index) of the substring from the full line. Such that the result would be as follows:__DATA__ ABCD EFGH
The following script of mine are unable to obtain those results.$VAR1 = { '0' => [ 'AB', EF ], '1' => [ 'BC', 'FG' ], '2' => [ 'CD', 'GH', ] };
Please advice how can I approach this problem. Thanks so much beforehand.#!/usr/bin/perl -w use strict; use Data::Dumper; my $enum_size =0; my %hash; my $sub_length = 2; my $lmer; while( <DATA> ) { chomp; my @array; $enum_size = length ($_) - $sub_length +1; for (my $j =0 ;$j <$enum_size ;$j++) { $lmer = substr ($_, $j, $sub_length); push @array, $lmer; $hash{$j}=[@array]; } } print Dumper \%hash; #Then do sth with the %hash
In reply to Getting columnwise substring from multiple lines by monkfan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |