Solved

Perl include output

Posted on 2000-04-08
4
223 Views
Last Modified: 2013-12-25
I have ASP pages that load in standard headers & footers using the following:

<!--#include virtual="/headers/header.inc" -->


Now I have 1 perl script (someone gave me) that I want to include the same headers and footers as I do in my ASP page.

The current static code the perl script generates is:
print "<HEAD>\n";
print "\t<TITLE>Telephone Directories Search Results</TITLE>\n";
print "</HEAD>\n\n";

What do I need to do to output the code from the above include  file (after the title)?

Thanks!
David
0
Comment
Question by:david_levine
  • 2
4 Comments
 

Expert Comment

by:akf
ID: 2696627
# Here's one way. Note that if it fails to open the include file,
# it will put a comment in your HTML saying why -- so look at the source
# if you don't see your file.
#
# You'll need to include the full path to header.inc.

my $incfile = "/fullpath/headers/header.inc";  # EDIT PATH
open (INFILE, "<$incfile") || print "<!-- couldn't open $incfile: $! -->\n" ;
                   
my $buf;
 
  { local ($/) = undef ;   # slurp entire file (not one line at a time)
     $buf = <INFILE>;
  }

close INFILE;

print $buf;


0
 
LVL 84

Accepted Solution

by:
ozo earned 75 total points
ID: 2697273
#you can also just
print <INFILE>;
#to slurp entire file and print it without having to set $/
#but it may be more efficient to print it one line at a time:
print while( <INFILE> );
#so you don't need to load the entire file into memory before you can start printing
0
 
LVL 9

Author Comment

by:david_levine
ID: 2697602
Thanks to the both of you!

I've adjusted the points from 75 down to 50 and will give the 50 to akf and post another question in this section for ozo for an additional 50.

Thanks again
0
 
LVL 9

Author Comment

by:david_levine
ID: 2697603
Oops... clicked the wrong button! :(

akf... I'll post your points as a new question in this section.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question