469,289 Members | 2,273 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,289 developers. It's quick & easy.

Generate a Table of contents using file open loop not working.

I am looking to build a regular expression that will match pTOC(somenumber)
where the number varies between 1& ten, this is to generate a table of contents file that I desperately need to display in my online help tab within an existing web application. I am still fairly new to perl if anyone could help me do this I will be forever in your debt.
existing code that needs to be fixed for new file.
Expand|Select|Wrap|Line Numbers
  1. if ( $Request->ServerVariables("SERVER_NAME")->item() =~ /mlxhelp/ ) {
  2.         my $toc_file = ( $Session->{'usrType'} eq 'Pro' ) ? 'c:\SupportWeb\NerfHerder\Content\HELP\PRO\TOC.html' : 'c:\SupportWeb\NerfHerder\Content\HELP\STD\TOC.html';
  3. my $user_type = uc $Session->{'usrType'};
  4.  
  5. open TOC, $toc_file;
  6. my @toc_lines = <TOC>;
  7. close TOC;
  8.         foreach my $line ( @toc_lines ) { 
  9.             $content .= qq^<rlink tab="Help" script="frames['help_iframe'].location.href='Content/HELP/$user_type/$1'" title="$3">
  10.                     </rlink>^ if ( $line =~ /<p class="pTOC1"><a href="(.*?)"\s+target="(.*?)">(.*?)<\/a>/ );
  11.         }
  12.         $content .= '</leftIndex>';
  13.  
  14.     }
The new file is in a different location, which has already been adjusted for, user_type is a variable which switches location between standard product and an optional upgrade product (not needed for new product at all and has been removed) $1 should be taking pTOC and re-writing it to leftIndex which is of course the left index of a frameset..
Sep 21 '07 #1
5 1291
KevinADC
4,059 Expert 2GB
This should get you started:

Expand|Select|Wrap|Line Numbers
  1. open TOC, $toc_file;
  2. my @toc_lines = <TOC>;
  3. close TOC;
  4. foreach my $line ( @toc_lines ) {
  5.    if ( $line =~ /<p class="(pTOC\d+)"><a href="(.*?)"\s+target="(.*?)">(.*?)<\/a>/ ) {
  6.       $content .= qq{<rlink tab="Help" script="frames['help_iframe'].location.href='Content/HELP/$user_type/$1'" title="$3"></rlink>};
  7.    }
  8.    $content .= '</leftIndex>';
  9. }
Sep 21 '07 #2
This should get you started:

Expand|Select|Wrap|Line Numbers
  1. open TOC, $toc_file;
  2. my @toc_lines = <TOC>;
  3. close TOC;
  4. foreach my $line ( @toc_lines ) {
  5.    if ( $line =~ /<p class="(pTOC\d+)"><a href="(.*?)"\s+target="(.*?)">(.*?)<\/a>/ ) {
  6.       $content .= qq{<rlink tab="Help" script="frames['help_iframe'].location.href='Content/HELP/$user_type/$1'" title="$3"></rlink>};
  7.    }
  8.    $content .= '</leftIndex>';
  9. }
Thanks kevin, it still isn't working for me but I appreciate the help, I am going over to my buddies who is also a web designer (he has a lot more experience than i do with perl maybe he can help me out). If if find what the problem is I will write back and let you know.
Oct 4 '07 #3
This should get you started:

Expand|Select|Wrap|Line Numbers
  1. open TOC, $toc_file;
  2. my @toc_lines = <TOC>;
  3. close TOC;
  4. foreach my $line ( @toc_lines ) {
  5.    if ( $line =~ /<p class="(pTOC\d+)"><a href="(.*?)"\s+target="(.*?)">(.*?)<\/a>/ ) {
  6.       $content .= qq{<rlink tab="Help" script="frames['help_iframe'].location.href='Content/HELP/$user_type/$1'" title="$3"></rlink>};
  7.    }
  8.    $content .= '</leftIndex>';
  9. }
Kevin I think the problem is the characters in the helpfile, I noticed that the previous TOC had regular links some of the links in the new toc are like this example below would this cause the re-write to fail and if so how would i adjust so it works again?
<a href="gettingstarteda3.html#wp1318504" target="Tempo_help_frame">

etc.
Oct 5 '07 #4
KevinADC
4,059 Expert 2GB
Can you post a sample of the real data you are trying to parse?
Oct 5 '07 #5
Can you post a sample of the real data you are trying to parse?
I also am having problems with switching from one to the other.
what I currently have switches from a free subscription to a pay for or to (tempo)
I would like to just display tempo if (site is eq to (list of sites) otherwise it should do the old test without the tempo element. .
The previous coder loved inline if statements (which I absolutely hate, because I find them very confusing. I would like to rewrite not to use these, but I am so new I am not sure how to)

Expand|Select|Wrap|Line Numbers
  1. <h2 class="pTOCTitle">Table of Contents</h2>
  2.  <p class="pTOC1"><a href="Tempo_help-08-1.html" target="Tempo_help_frame">Getting Started</a></p>
  3.   <p class="pTOC2"><a href="gettingstarted2.html" target="Tempo_help_frame">Signing In and Out</a></p>
  4.   <p class="pTOC2"><a href="gettingstarteda3.html" target="Tempo_help_frame">What's On the Home Page?</a></p>
  5.    <p class="pTOC3"><a href="gettingstarteda3.html#wp1318504" target="Tempo_help_frame">Header Bar Controls</a></p>
  6.    <p class="pTOC3"><a href="gettingstarteda3.html#wp1318527" target="Tempo_help_frame">Main Menu Bar</a></p>
  7.    <p class="pTOC3"><a href="gettingstarteda3.html#wp1318559" target="Tempo_help_frame">My Sidebar</a></p>
  8.    <p class="pTOC3"><a href="gettingstarteda3.html#wp1318563" target="Tempo_help_frame">Prospecting Matches</a></p>
  9.    <p class="pTOC3"><a href="gettingstarteda3.html#wp1318574" target="Tempo_help_frame">Find a Listing</a></p>
  10.    <p class="pTOC3"><a href="gettingstarteda3.html#wp1318585" target="Tempo_help_frame">Hotsheet</a></p>
  11.    <p class="pTOC3"><a href="gettingstarteda3.html#wp1318599" target="Tempo_help_frame">Inventory Watch</a></p>
  12.   <p class="pTOC2"><a href="gettingstarted4.html" target="Tempo_help_frame">Using the MLS, Broker and Office Tabs</a></p>
  13.   <p class="pTOC2"><a href="gettingstarted5.html" target="Tempo_help_frame">Identity Sharing</a></p>
  14.  <p class="pTOC1"><a href="Tempo_help-02-1.html" target="Tempo_help_frame">The Basics</a></p>
  15.   <p class="pTOC2"><a href="basics2.html" target="Tempo_help_frame">A Look at the Main Interface</a></p>
  16.    <p class="pTOC3"><a href="basics2.html#wp1308985" target="Tempo_help_frame">Collapsing/Expanding the Main Menu</a></p>
  17.    <p class="pTOC3"><a href="basics2.html#wp1309017" target="Tempo_help_frame">Links</a></p>
  18.   <p class="pTOC2"><a href="basics3.html" target="Tempo_help_frame">Field Related Controls</a></p>
  19.  
Oct 9 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Dave Nouwens | last post: by
3 posts views Thread by Mike | last post: by
3 posts views Thread by Phil Rutter | last post: by
10 posts views Thread by John Smith | last post: by
4 posts views Thread by Kevin Blount | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.