Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

printing out hash

by grashoper (Monk)
on Nov 08, 2007 at 19:59 UTC ( #649789=perlquestion: print w/replies, xml ) Need Help??

grashoper has asked for the wisdom of the Perl Monks concerning the following question:

working on a larger problem broke down into smaller parts here is whats working as well as whats not. 1) succesfully setup a hash with structure of topics as key and values are the relevant html files, reading in the topic value from the query string and matching it to my %hash verified this part is working by writing out to my browser forced an error to capture the write now I need to pass the target which I called $nightmare to my help subroutine.. Help subroutine--> passes startpoint into mLeftIndex, which sets which helpfile and provides content to you guessed it the leftIndex of a frameset.(I know I hate Iframes but thats what I am stuck with). I cannot use strict as I have a problem with it that I have not been able to figure out as of yet.
<% @Language="PerlScript" %> <!--#Include File="base/base.asp"--> <!--#Include File="base/core.asp"--> <!--#Include File="base/helper.asp"--> <!--#Include File="base/modules.asp"--> <% my $User = $Request->item("Login")->item(); my $Site = $Request->item("Site")->item(); $topic= $Request->item("Topic")->item(); my $Referer = $Request->ServerVariables("HTTP_REFERER")->item(); use CGI; use ASP; use OLE; $query= new CGI; my %ttopics = ( home => 'TEMPO%205%20Help%20Topics-01-1.html', listingmgr => 'TEMPO%205%20Help%20Topics-06-1.html', ); if (!defined($topic)) { # ...handle error... } $nightmare = $ttopics{$topic}; if (!defined($target)) { # ...handle error... } $Response->Write("Topic is $topic\n"); $Response->Write("my target is $nightmare\n"); }
Sub tHelp-> sets startpoint.
sub tHelp { my $str = ""; my $startpoint=$nightmare=@_; # Are We Tempo? if ($Session->{'usrType'} eq 'Std') { if ($Request->ServerVariables("SERVER_NAME")->item()=~/tempohelp/i +) { my $target='Tempo%20help_frame'; $str .= shadowBox("Tempo Help", qq^<help_iframe name="$target" +startpoint="$startpoint"/>^ , ($g_docWidth/5*4-(2*$g_docSpace))); return $str; } } }
Here is main which calls thelp.
sub pMain { my ($dWidth) = @_; my $str = ""; my $xmlFSO = CreateObject OLE "Scripting.FileSystemObject"; if ($Request->item("xURL")->item()) { lg("ACTIVITY","REFERRAL:".$Request->item("xURL")->item()); $str .= "<xURL href=\"".$Request->item("xURL")->item()."\"/>"; } if ($Request->item("xResource")->item()) { lg("ACTIVITY","Resource:".$Request->item("xResource")->item()); $str .= "<xResource href=\"".$Request->item("xResource")->item() +."\" height=\"".$Request->item("xRh")->item()."\" width=\"".$Request- +>item("xRw")->item()."\"/>"; } SWITCH: { if ($Request->item("View")->item() eq "Logout"){ $str .= mLogout +(); last SWITCH; } if ($Request->item("Tab")->item() eq "Help"){ $str .= +&tHelp($nightmare); last SWITCH; } if ($Request->item("Tab")->item() eq "Support"){ $str .= tSuppor +t(); last SWITCH; } if ($Request->item("Tab")->item() eq "Admin"){ $str .= tAdm +in(); last SWITCH; } } return $str; }
Sub document that outputs doc.
$xmlPage = "<document here=\ queryString=\"$queryString\" docWidth=\"$dWidth\" scWidth=\"".$Session->{'screenX'}."\" scHeight=\"".$Session->{'screenY'}."\" docSpace=\"$g_docSpace\" uClass=\"".$uClass."\" uTitle=\"".$1."\" uDesc=\"".$2."\""; $xmlPage .= $Session->{'statsRights'} ? " statsRights=\"".$Session +->{'statsRights'}."\"" : ""; $xmlPage .= $Session->{'adminRights'} ? " adminRights=\"".$Session +->{'adminRights'}."\"" : ""; $xmlPage .= " date=\"$year".pad($mon,2).pad($mday,2)."\" wDay=\"$wday\" time=\"".pad($hour,2).pad($min,2)."\" + cBackground=\"$c_Background\" cElement=\"$c_Element\" cFrame=\"$c_Frame\" cShadow=\"$c_Shadow\" cLink=\"$c_Link\" cText=\"$c_Text\">\n"; $xmlPage .= css(); $xmlPage .= admin(); $xmlPage .= config(); $xmlPage .= jscripts(); $xmlPage .= adverts(); $xmlPage .= header(); $xmlPage .= body($dWidth); $xmlPage .= footer(); $xmlPage .= "\n</document>"; return $xmlPage; }
Here is mLeftIndex();
sub mLeftIndex { my $str = ""; my $logoutLink = "<link tab=\"\" view=\"Logout\" title=\"Logout\"/ +>"; my $content = '<leftIndex>'; if ( $Request->ServerVariables("SERVER_NAME")->item() =~ /mlxhelp/ + ) { my $toc_file = ( $Session->{'usrType'} eq 'Pro' ) ? 'e:\Suppor +tWeb\Content\HELP\PRO\TOC.html' : 'e:\SupportWeb\Content\HELP\STD\TOC +.html'; my $user_type = uc $Session->{'usrType'}; open TOC, $toc_file; my @toc_lines = <TOC>; close TOC; foreach my $line ( @toc_lines ) { $content .= qq^<rlink tab="Help" script="frames['help_ifra +me'].location.href='Content/HELP/$user_type/$1'" title="$3"> </rlink>^ if ( $line =~ /<p class="pTOC1"><a href= +"(.*?)"\s+target="(.*?)">(.*?)<\/a>/ ); } $content .= '</leftIndex>'; } if ( $Request->ServerVariables("SERVER_NAME")->item() =~ /tempohelp/ ) + { my $toc_file = ( $Session->{'usrType'} eq 'Pro' ) ? 'e:\Suppor +tWeb\Content\HELP\PRO\TOC.html' : 'e:\SupportWeb\Content\help\tpo\def +ault\TOC.html'; my $user_type = uc $Session->{'usrType'}; if ($user_type='STD') {$user_type='TPO\/default\/'} open TOC, $toc_file; my @toc_lines = <TOC>; close TOC; foreach my $line ( @toc_lines ) { $content .= qq^<rlink tab="Help" script="frames['help_ifra +me'].location.href='Content/HELP/$user_type/$1'" title="$3"> </rlink>^ if ( $line =~ /<p class="pTOC\d"><a href +="(.*?)"\s+target="(.*?)">(.*?)<\/a>/ ); } $content .= '</leftIndex>'; }
function that calls transforms
sub transform { my $trns = $Server->MapPath("Transforms/pLogin.xsl"); if ($Session->{'isAuthenticated'}) { getMOTD(); SWITCH: { if ($Request->item("View")->item() eq "Resources") { $trns = $Server->MapPath("Transforms/tResources.xsl"); last SWITCH; } if ($Request->item("Tab")->item() eq "Support") { $trns = $Server->MapPath("Transforms/tSupport.xsl"); last SWITCH; } if ($Request->item("Tab")->item() eq "Help") { $trns = $Server->MapPath("Transforms/tHelp.xsl"); last SWITCH; } if ($Request->item("Tab")->item() eq "Training") { $trns = $Server->MapPath("Transforms/tTraining.xsl"); last SWITCH; } if ($Request->item("Tab")->item() eq "Trainers") { $trns = $Server->MapPath("Transforms/tTrainers.xsl"); last SWITCH; } if ($Request->item("Tab")->item() eq "Admin") { $trns = $Server->MapPath("Transforms/tAdmin.xsl"); last SWITCH; } $trns = $Server->MapPath("Transforms/pMain.xsl"); } } return $trns; }

Replies are listed 'Best First'.
Re: printing out hash
by planetscape (Chancellor) on Nov 08, 2007 at 22:50 UTC

    You may want to take a look at the replies to How can I visualize my complex data structure?; and in particular, the reference to I've got a hash of hashes how do i get my values out, which shows how to iterate over an arbitrary complex data structure.

    I'd really recommend, however, some basic knowledge first... One of the best discussions of complex data structures, and how to access their innards , is to be found in Chapter 3. References and complex data structures of perlinter.pdf, available from Perl Training Australia. The OP would probably want the most current version of the course notes, though, which have been reworked into progperl.pdf, available from the same page noted above.

    HTH,

    planetscape
Re: printing out hash
by philcrow (Priest) on Nov 08, 2007 at 20:03 UTC
    You are missing a paren in the last while:
    while (my ($home, $topics)=each(%topics) ) { # ^
    I didn't read the rest.

    Phil

    The Gantry Web Framework Book is now available.
Re: printing out hash
by graff (Chancellor) on Nov 09, 2007 at 02:32 UTC
    I think it will help if you add use strict; -- in particular, when you do that, and add "my" where necessary, you will find that you misspelled the name of your hash in the while() loop condition:
    while (my ($home, $topics)=each(%topics)){ # should be %ttopics
    Also, you have this funny thing in the "tHelp" sub:
    sub tHelp {\%ttopics my $startpoint=$target;
    What is "\%ttopics" doing there? Even if that isn't a syntax error, I can't imagine what it's supposed to do, and I expect it is a mistake. Actually, the tHelp sub as a whole makes no sense. What is that sub supposed to do? Where is it called from? Should you perhaps be providing some parameters when you call it? --e.g.:
    # some where in the part that calls tHelp: tHelp( $param1, \@array ); # or whatever... # in tHelp itself: sub tHelp { my ( $param, $aref ) = @_; ... }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://649789]
Approved by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2021-05-15 08:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (150 votes). Check out past polls.

    Notices?