hipnoodle has asked for the wisdom of the Perl Monks concerning the following question:
sub makeTable { my ($ref, $cols) = @_; my $one_col = ""; #pull in ref. to hash (doc. name, URL) my $links_ref = ($cols =~ /MPS/) ? &getMPSlinks : ""; #----make column titles, and begin html code for table my @cols = split (/,/,$cols); foreach (@cols) {$labels .= qq|<td>$_</td>|;} my $table = qq|<table class="center"><tr class="table_labels">$lab +els</tr>|; foreach (@$ref) { #loop thru array of arrays, inside we'll take ea +ch array and break out into table $table .= ++$count % 2 == 1 ? qq|<tr class="row_light">| : qq|< +tr class="row_dark">|; #alaternate row colors #---Build tables here------------------------------------------ +----- if ($form{"query"} eq "deptcodes") { my $doc_num = qq|@$_[2]|; #PROBLEM CHILD ON NEXT LINE $table .= qq|<td>@$_[0]</td><td>@$_[1]</td><td><a href="$ +links_ref->{@$_[0]}" target="_blank">@$_[2]</a></td>|; + } } $table .= "</table>"; return($table); } #this returns a ref to a hash. key is doc. name, value is URL sub getMPSlinks { our %mps_hash=(); my ($one_mps, $one_url) = ""; open(HANDLE, "< $cgi_path/mpslinks.txt") or die "***Couldn't +open $path for reading: $!\n"; while (<HANDLE>) { ($one_mps, $one_url) = split (/\|/,$_); $mps_hash{$one_mps} = "$one_url"; #print "<strong>$one_mps</strong><br> $one_url"; } close (HANDLE); return (\%mps_hash); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: trouble dereferencing a hash reference
by bobf (Monsignor) on Mar 21, 2006 at 18:15 UTC |