Hi there,
I have a routine returning a perl reference and I am trying to figure
out how to properly use the hash tables in the main section of my perl
proggie.
--- from the main program
my $templateConfiguation = &readConfigTemplate($templateConfigFilename,
$sortedTemplateConfigFilename);
.... and later on how do I properly use the hash $templateConfiguation ....
} else {
print DIFF "d> $key" if !exists
($templateConfiguation{$templateType}{$key});
print MATCH "m> $key" if exists
($templateConfiguation{$templateType}{$key});
}
----- from the subroutine ----
sub readConfigTemplate {
my $templateConfigFilename = shift;
my $sortedTemplateConfigFilename = shift;
my %templateConfiguation = ();
### Read template file
open (DATA, $templateConfigFilename) || die("Could not open file
$templateConfigFilename!");
### save output of sorted template file
open (OUTPUT, ">$sortedTemplateConfigFilename") || die("Could not
open file $sortedTemplateConfigFilename!");
@lines = <DATA>;
@lines = sort (@lines);
my $linecount = 0;
my $templateType = undef;
### decide if the template type is blah1 or blah2
for my $line (@lines) {
if ($templateConfigFilename =~ /blah1/ && !$templateType) {
$templateType = "blah1";
last;
} elsif ($templateConfigFilename =~ /blah2/ && !$templateType) {
$templateType = "blah2";
last;
}
}
### make sure some $templateType is defined
die ("Someting broken in $templateConfigFilename\n") if !$templateType;
foreach my $line (@lines) {
#### remove end line spacing
$line =~ s/\r//;
#### remove start line spacing
$line =~ s/^\s+//;
next if $line !~ /^blahblah/;
print OUTPUT $line;
$templateConfiguation{$templateType}{$line} = $line;
$linecount++;
}
close (DATA);
close (OUTPUT);
return \%templateConfiguation;
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/