in reply to Getting columnwise substring from multiple lines
Update: It just struck me that using a hash for this is silly. String offsets are integers that run from 0!
#! perl -slw use strict; use Data::Dumper; my @hash; while( my $line = <DATA> ) { chomp $line; push @{ $hash[ $_ ] }, substr $line, $_, 2 for 0 .. length( $line ) -2; } print Dumper \@hash; __DATA__ ABCDEFGHIJKLM abcdefghijklm NOPQRSTUVWXYZ nopqrstuvwxyz
Ignore the code below.
#! perl -slw use strict; use Data::Dumper; my %hash; while( my $line = <DATA> ) { chomp $line; push @{ $hash{ $_ } }, substr $line, $_, 2 for 0 .. length( $line ) -2; } print Dumper \%hash; __DATA__ ABCDEFGHIJKLM abcdefghijklm NOPQRSTUVWXYZ nopqrstuvwxyz
|
|---|