sub make_hash { my %opt = @_; my $file = $opt{'file'} && ref($opt{'file'}) eq 'ARRAY' ? data_file(@{$opt{'file'}}) : $opt{'file'}; open(my $fh, '<', $file) || die "Can not open $file $!"; my @headings = $opt{'headings'} ? @{$opt{'headings'}} : ('heading'); my %hash; while (my $line = <$fh>) { chomp $line; die "This file is not for Util::Data! Stopped $!" if $line =~ /no Util::Data/i; my @values = split(/\|/,$line); my $key = scalar @headings > 1 ? $values[0] : shift @values; my $n = 0; for my $r_heading (@headings) { if (defined($values[$n]) && length($values[$n]) > 0) { my $split = $r_heading =~ /\+$/ ? 1 : 0; (my $heading = $r_heading) =~ s/\+$//; my $value = $split == 1 ? [map { $_ =~ s/^ //; $_ } split(/;/,$values[$n])] : $values[$n]; if (scalar @headings > 1) { $hash{$key}{$heading} = $value; } else { $hash{$key} = $value; } } $n++; } } return \%hash; } sub alpha_hash { my ($org_list, $opt) = @_; my %alpha_hash; for my $org_value (keys %{$org_list}) { my $alpha = !$opt->{article} ? first_alpha($org_value) : substr($org_value, 0, 1); $alpha_hash{$alpha}{$org_value} = $org_list->{$org_value}; } return \%alpha_hash; }