<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>masterrex</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/masterrex/" />
    <link rel="self" type="application/atom+xml" href="http://blogs.perl.org/users/masterrex/atom.xml" />
    <id>tag:blogs.perl.org,2009-11-03:/users/masterrex//365</id>
    <updated>2010-06-21T00:41:52Z</updated>
    <subtitle>A blog about the Perl programming language</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Pro 4.38</generator>

<entry>
    <title>PHP has include(index.php); what does Perl have? </title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/masterrex/2010/06/php-has-includeindexphp-what-does-perl-have.html" />
    <id>tag:blogs.perl.org,2010:/users/masterrex//365.656</id>

    <published>2010-06-21T00:13:44Z</published>
    <updated>2010-06-21T00:41:52Z</updated>

    <summary>I&apos;ve done a little more with Perl and web design, but I&apos;ve encountered a problem that has left me a bit perplexed. There&apos;s something PHP does that I&apos;m sure Perl CAN do, but I&apos;m just not sure how. That said,...</summary>
    <author>
        <name>masterrex</name>
        <uri>http://www.masterrex.com</uri>
    </author>
    
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/masterrex/">
        <![CDATA[<p>I've done a little more with Perl and web design, but I've encountered a problem that has left me a bit perplexed. There's something PHP does that I'm sure Perl CAN do, but I'm just not sure how. That said, I'm not a huge fan of PHP, and to be quite honest the only function I've utilized has been include(), which is what I need to replicate. As you know, being able to standardize a page layout (header, body, footer) with separate pages makes things much easier to update. Instead of correcting/adding a navigation link to twenty pages, you only make one change! However, using PHP within a Perl script (without the aid of the PHP or PHP::Include modules - my host doesn't have 'em installed) doesn't work as the browser doesn't get the chance to parse/execute the PHP. </p>

<p>Some people have pointed me in the direction of the system() function, but I don't think that's quite what I need (please correct me if I'm wrong).  Also, I don't really know how I'd use it - there's nothing to really 'execute' in the PHP I want; I guess all I really need is to read in a .php or .html file and store it to a scalar variable and then place the variable where I would normally use <pre><code>&lt;?php include(); ?&gt;</code></pre> </p>

<p>In that case, I guessed that just opening the file and storing it to some array/list would allow me to simply print the array, but I can't figure out how to do it!</p>

<p>I resorted to Google, <a href="http://www.daniweb.com/forums/thread67060.html">and came up with this page.</a> </p>

<p>I've tried every method there, but I always end up with a blank page.  Does anyone have insight on this? </p>

<p>For reference, I've been testing this with:</p>

<p>http://www.masterrex.com/test/include/test.pl<br />
http://www.masterrex.com/test/include/i/head.html</p>

<pre><code>

<p>print "Content-type: text/html\n\n";<br />
open (HTML, "&lt;/i/head.html");<br />
print &lt;HTML&gt;;<br />
close (HTML);  </p>

<p>############</p>

<p>open (HTMLDOC, "&lt;/i/head.html");<br />
flock (HTMLDOC, 1);<br />
my @htmlFile = &lt;HTMLDOC&gt;;<br />
close (HTMLDOC);<br />
print "Content-type: text/html\n\n";<br />
foreach (@htmlFile) {<br />
print $_;<br />
}</p>

<p></code></pre></p>

<p>Also, if I were to not use a bareword, what kind of variable would I end up using? I've read somewhere that opening a file to a scalar only works if there are no return characters in the file - so I'd assume that I'd want an array/list.  I'm a bit confused at this point :P</p>]]>
        
    </content>
</entry>

<entry>
    <title>Hello, World. /cliché</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/masterrex/2010/05/hello-world-cliche.html" />
    <id>tag:blogs.perl.org,2010:/users/masterrex//365.599</id>

    <published>2010-05-31T18:19:50Z</published>
    <updated>2010-05-31T22:36:41Z</updated>

    <summary>I&apos;ve only recently taken on the tremendous task of learning Perl (with the aide of O&apos;Reilly&apos;s Learning Perl). I have a little background in programming as I am a Computer Engineering &amp; Computer Science student at the Florida Institute of...</summary>
    <author>
        <name>masterrex</name>
        <uri>http://www.masterrex.com</uri>
    </author>
    
    <category term="date" label="date" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="diary" label="diary" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="journal" label="journal" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="simple" label="simple" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/masterrex/">
        <![CDATA[<p>I've only recently taken on the tremendous task of learning Perl (with the aide of O'Reilly's <em>Learning Perl</em>).  I have a little background in programming as I am a Computer Engineering & Computer Science student at the Florida Institute of Technology. Actually, I <em>was</em> a student there. I can't quite afford it at this point, and I'm going to attempt to transfer elsewhere (UCF, USF, UF? Something with a U and an F, I'd suppose).</p>

<p>Well, on to something a bit more on-topic. I'm midway through Chapter 5 in <em>Learning Perl</em> and I felt the need to create something that the book didn't explicitly tell me to. I eventually want to build my own forums software, but this small 'Journal' or 'Diary' script will have to do for now. </p>

<blockquote>#! /usr/bin/perl

<p>print "Press CTRL-D to end journal entry.\n";<br />
my $success = open LOG, ">>logfile";<br />
if ( ! $success) {<br />
	die "Cannot create logfile: $!";<br />
}</p>

<p>select LOG;<br />
print "\n\n", scalar localtime(), "\n";<br />
print &lt;STDIN&gt;;</blockquote></p>

<p><br />
I'm sort of surprised that this blog software doesn't have a specific 'code' tag. Perhaps I'm missing something? </p>

<p>The script above isn't very complex, and if you're reading this blog I'm sure you've already noticed that what I've done in a few lines could have been done a single line. Unlike most programmers, I prefer to write things out the long way for readability's sake. I wonder if Larry Wall would hate me for it? </p>

<p>Edit - Thanks for the input! The script was simplified to four simple lines:</p>

<blockquote>

<p>print "Press CTRL-D to end journal entry.\n";<br />
open my $log, '>>', 'logfile' or die "Cannot open logfile: $!";<br />
print {$log} "\n\n", scalar localtime(), "\n"; <br />
print {$log} &lt;STDIN&gt;;</p>

</blockquote>

<p>Also, there's an alternative to specifying {$log} each time:<blockquote>select $log;<br />
print "\n\n", scalar localtime(), "\n";<br />
print &lt;STDIN&gt;;<br />
</blockquote></p>]]>
        
    </content>
</entry>

</feed>
