Results 1 to 12 of 12
  1. #1
    Newbie Affiliate Ian's Avatar
    Join Date
    January 18th, 2005
    Posts
    1,540
    Include function in PERL?
    Hey, is there an equivalant function to PHP or SHTML's include in PERL? I would hate to have to code HTML using PRINT!

    TIA!

  2. #2
    Moderator MichaelColey's Avatar
    Join Date
    January 18th, 2005
    Location
    Mansfield, TX
    Posts
    16,232
    Look into modules and packages. That'll do what you want. Once you build a module, you can "use" it in other programs. Here's a fairly simple tutorial.

    You can find tons of packages that others have written with CPAN. See Installing CPAN Modules.
    Michael Coley
    Amazing-Bargains.com
     Affiliate Tips | Merchant Best Practices | Affiliate Friendly? | Couponing | CPA Networks? | ABW Tips | Activating Affiliates
    "Education is the most powerful weapon which you can use to change the world." Nelson Mandela

  3. #3
    Newbie Affiliate Ian's Avatar
    Join Date
    January 18th, 2005
    Posts
    1,540
    Hi Michael,

    Thanks for the reply. Unfortunately, this is way beyond me.

    Back to adding print " & "; to every line...

  4. #4
    I like traffic lights
    Join Date
    January 18th, 2005
    Location
    Southern hemisphere - away from Fukushima
    Posts
    2,936
    Errrr. "Print" by default sends output to standard output - in the case of a CGI script, the HTML being sent by the server to the browser. So "print" is what is usually used in PERL to output HTML.

    Or are you talking about how PHP is used in an embedded within the HTML context?

  5. #5
    Newbie Affiliate Ian's Avatar
    Join Date
    January 18th, 2005
    Posts
    1,540
    No, I am running an old PERL search script and need to dump the search results into the site's look and feel (template). Looks like I need to output HTML in the actual PERL script. Got it to work but that means everytime I update the template, I have to update the PERL code manualy.

  6. #6
    Moderator MichaelColey's Avatar
    Join Date
    January 18th, 2005
    Location
    Mansfield, TX
    Posts
    16,232
    So you're needing to read a file and output it?

    Code:
    open FN, "/path/to/file"
    while ($line = <FN>) {
       print $line;
    }
    close FN;
    Michael Coley
    Amazing-Bargains.com
     Affiliate Tips | Merchant Best Practices | Affiliate Friendly? | Couponing | CPA Networks? | ABW Tips | Activating Affiliates
    "Education is the most powerful weapon which you can use to change the world." Nelson Mandela

  7. #7
    Member SeanW's Avatar
    Join Date
    July 28th, 2005
    Posts
    69
    Quote Originally Posted by Affiliate Ian
    Hey, is there an equivalant function to PHP or SHTML's include in PERL? I would hate to have to code HTML using PRINT!

    TIA!
    To include code you can use "require".

    If you want to avoid prints, use here documents:

    print <<FOO;
    This
    text
    gets printed
    FOO


    Sean

  8. #8
    I like traffic lights
    Join Date
    January 18th, 2005
    Location
    Southern hemisphere - away from Fukushima
    Posts
    2,936
    Quote Originally Posted by MichaelColey
    So you're needing to read a file and output it?

    Code:
    open FN, "/path/to/file"
    while ($line = <FN>) {
       print $line;
    }
    close FN;
    or....

    open FN , "blah";
    print while (<FN>);

    :^)

    $_ is your friend.

  9. #9
    Newbie Affiliate Ian's Avatar
    Join Date
    January 18th, 2005
    Posts
    1,540
    ok, i thikn i opened up a can of worms. here is what i want to do, let's see if this is possible.

    I am using Matt's search script. In the portion where I display the results, intead of just displyaing the results in a simple HTML page, I want to take the results section and have it show up in the middle of my website template. So I don't mind coding in the template by hand using Print " but I want to be able to include my left hand menu, top navigation from a .html file so that when I update the site, the Perl search gets updated when the results are pulled when someone accesses the search.

    Hope that made sense....

  10. #10
    Moderator MichaelColey's Avatar
    Join Date
    January 18th, 2005
    Location
    Mansfield, TX
    Posts
    16,232
    What does your template look like, and where is it stored? For instance, does it look like:

    <html>
    ...html code...
    {Content}
    ...html code...
    </html>

    Where "{Content}" gets replaced with the actual page content?

    If so, basically you just need to read through the template file to get the part before and after "{Content}", then print the "before" part at the beginning of the script and the "after" part at the end of the script.
    Michael Coley
    Amazing-Bargains.com
     Affiliate Tips | Merchant Best Practices | Affiliate Friendly? | Couponing | CPA Networks? | ABW Tips | Activating Affiliates
    "Education is the most powerful weapon which you can use to change the world." Nelson Mandela

  11. #11
    Newbie Affiliate Ian's Avatar
    Join Date
    January 18th, 2005
    Posts
    1,540
    Quote Originally Posted by MichaelColey
    What does your template look like, and where is it stored? For instance, does it look like:

    <html>
    ...html code...
    {Content}
    ...html code...
    </html>

    Where "{Content}" gets replaced with the actual page content?

    If so, basically you just need to read through the template file to get the part before and after "{Content}", then print the "before" part at the beginning of the script and the "after" part at the end of the script.
    Yes, that is the idea. And I have done that for evey single line above and below {content}. But, within my ...html code..., I use SSI to include left menu, righ menu etc... I am not sure how inside the perl script, I can use an include function within my HTML. Any ideas?

  12. #12
    Moderator MichaelColey's Avatar
    Join Date
    January 18th, 2005
    Location
    Mansfield, TX
    Posts
    16,232
    Email me your existing script and tell me the full path and name to each file that you're wanting to include. You can find my email address on the "Contact" page of my site. (The link to the contact page is in my bottom nav bar on my site below.)
    Michael Coley
    Amazing-Bargains.com
     Affiliate Tips | Merchant Best Practices | Affiliate Friendly? | Couponing | CPA Networks? | ABW Tips | Activating Affiliates
    "Education is the most powerful weapon which you can use to change the world." Nelson Mandela

  13. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Perl Help...
    By eggerda in forum Programming / Datafeeds / Tools
    Replies: 7
    Last Post: July 22nd, 2003, 05:40 AM
  2. Perl help.
    By mewmew in forum Programming / Datafeeds / Tools
    Replies: 2
    Last Post: October 10th, 2002, 03:41 PM
  3. RE: Learning Perl
    By Gordon in forum Programming / Datafeeds / Tools
    Replies: 3
    Last Post: October 4th, 2002, 08:41 PM
  4. To include or not to include that is the question
    By Heyder in forum Search Engine Optimization
    Replies: 8
    Last Post: October 1st, 2002, 05:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •