monkfan has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Getting columnwise substring from multiple lines
by BrowserUk (Patriarch) on Dec 23, 2004 at 06:15 UTC | |
|
Re: Getting columnwise substring from multiple lines
by Zaxo (Archbishop) on Dec 23, 2004 at 06:32 UTC | |
|
Re: Getting columnwise substring from multiple lines
by Skeeve (Parson) on Dec 23, 2004 at 08:39 UTC | |
|
Re: Getting columnwise substring from multiple lines
by sasikumar (Monk) on Dec 23, 2004 at 06:48 UTC |