in reply to Methods to store content

Its easier to focus on each problem if you name each problem :) ... argument passing is how to do subroutines

readFile( 'Text1', \@array1, \@data1 ); readFile( 'Text1', \@array2, \@data2 ); compareTheseThings( \@array1, \@data1 , \@array2, \@data2 ); sub readFile { my( $filename, $arrayref, $dataref ) = @_; use autodie qw/ open close /; open my($fh), '<', $filename ; ... push @$arrayref, ...; push @$dataref, ...; ... close $fh; return; }

use Data::Dump qw/ dd /; ## this? { my( %RedText, %DerText ); $RedText{'Entry 1'}{D}=1; $RedText{'Entry 1'}{N}=2; $DerText{'Entry 3'}{N}=6; $DerText{'Entry 3'}{""}=7; ## uh oh, something fishy $DerText{'Entry 5'}{D}=4; ## uh oh, duplicates overwrite, no good $DerText{'Entry 5'}{D}=9; dd( \%RedText, \%DerText ); } ## maybe this? { my( %RedText, %DerText ); $RedText{'Entry 1'}{1}='D'; $RedText{'Entry 1'}{2}='N'; $DerText{'Entry 3'}{6}='N'; $DerText{'Entry 3'}{7}=''; $DerText{'Entry 5'}{4}='D'; $DerText{'Entry 5'}{9}='D'; dd( \%RedText, \%DerText ); }
So, if the number values are whats unique for each entry (no duplicates, no repeats), this hash of hashes
"entry_id", "fist_number", "second_letter" $hash{"entry_id"}{"fist_number"} = "second_letter"; $bothfiles{first_file}{"entry_id"}{"fist_number"} = "second_letter";

does this make sense to you?

  • Comment on Re: Methods to store content (choosing a data structure for comparing entries from two different files , hash)
  • Select or Download Code