How to Embed Perl in HTML

The convenience of embedding scripting code in HTML documents for web development is undeniable. Having a powerful language like Perl working just like PHP is a very good combination. Embedding Perl in HTML allows for many different things to happen inside a web page, from table creation to drawing content from a database of articles. You can embed Perl in HTML by installing extra software packages or using the software you already have.

Instructions

  1. Use Heredoc to Embed Perl

    • 1

      Write your HTML code in a "heredoc" quote. This is a quick way to embed Perl without the need for additional software. This type of quote (like a double or a single quote) is best for quoting very long, multiline strings. Simply encompass your HTML in these heredoc quotes, remembering the newline after the final END keyword:
      "print <

      Title


      END"

    • 2

      Add interpolated variables. Heredocs can have interpolated variables just like double quotes:
      "$title = "My cool webpage";
      print < $title
      END
      "

    • 3

      Add loops, as the same heredoc can be looped over multiple times. In this example, loop will print the numbers 1 through 10 in a table.
      "print <


      ENDfor( $i = 1; $i <= 10; $i++ ) {
      print <

      END
      }print <
      $i

      END
      "

    Use an Embedded Perl Interpreter

    • 4

      Install HTML::Embperl. This package can be installed via CPAN and configured to work with mod_perl and Apache.

    • 5

      Write a skeleton HTML document for testing:
      "
      test

      Content goes here

      "

    • 6

      Execute Perl code. This is just one of the meta-tags, and will execute perl code and produce no output. It should be used for variable assignment, loops and any other code that produces no output:
      "[- $a = 10 -]"

    • 7

      Produce output from Perl. The meta-tags will print anything within them, which is useful for outputting a variable:
      "

      $a = [+ $a +]

      "

    • 8

      Put it all together. Here is the table example with the embedded perl meta-tags:
      "


      [- for( $i = 1; $i <= 10; $i++ ) { -]

      [- } -]
      [+ $i +]
      "

Tips & Warnings

  • Starting and stopping the heredocs can be cumbersome. This is not the case with an embedded Perl interpreter.

Related Searches:

Comments

You May Also Like

  • Perl Tutorial for Printing HTML & Inline HTML Frames

    The Perl scripting language was designed to facilitate text manipulation and report processing. It features powerful regular expression capabilities, with a compact...

  • How to Embed Audio in HTML

    Embedding audio in a blog or website can provide users with many benefits. You can set the website or blog to automatically...

  • How to Embed Skype Within HTML

    Many Skype lovers use their accounts in lieu of a traditional phone. If you want to advertise your Skype contact info on...

  • How to Embed a PHP File in HTML

    PHP files are text files with the php extension. Similar to HTML files, a PHP file contains the code for a PHP...

  • How to Convert Perl Script to EXE

    The Perl programming language is an interpreted language. That means that the source code is evaluated when the program is run by...

  • How to Remove an Embedded Virus in a Setup File

    Viruses have become a major hazard when downloading any sort of file from the Internet. One problem is when a virus becomes...

  • What Is Font Embedding?

    Font embedding is a mildly controversial topic among font creators as it allows fonts to be sent along with documents to preserve...

  • How to Use Perl to Send HTML Email

    Sending a plain text email from a Perl script can be done in a straightforward manner. The process becomes more involved when...

  • Perl Script Calculation

    The following is a strategy guide to performing mathematical calculations using the Perl programming language. Included is a list of numerical operators,...

  • How to Remove the Perl File Extension

    Perl is a highly versatile scripting language used by programmers, system administrators and designers to create a wide variety of programs for...

  • Web Page Creation Shareware Tools

    PHP is a scripting language designed for web design, so the user can code a dynamic web page. The code works hand-in-hand...

  • How to Write CGI Scripts

    CGI (Common Gateway Interface) is not necessarily a programming language, but more of an intermediary function in website design. To use CGI,...

  • How to Embed TTF Fonts in CSS

    Embedded fonts are nothing new to Web design. Though font-replacement techniques such as Cufon and sIFR came into use around 2008, CSS...

  • MySQL Perl DBI Tutorial

    One of the most powerful features of Perl is its ability to process, parse, manipulate and format text and data, making it...

  • How to Embed Fonts Using CSS3

    Web designers have been limited by typography using only Web-safe fonts for many years. Alternatives previously included using images, Flash, JavaScript or...

  • How to Write Portable Perl Code

    Writing portable Perl code has plenty of advantages. One main advantage is that you can write it once and run it on...

  • How to Run Perl on a Laptop

    Running Perl on a laptop is as easy as downloading and installing a Perl distribution. On Windows or Mac, ActiveState's ActivePerl distribution...

Related Ads

Featured