Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HTML perl script
#1
Code:
#!/usr/bin/perl

if ($#ARGV != 1) {
    print q{
=============================================================
|                                                           |
|                  Coded by Ace - 2011                      |
|              http://www.techlifeforum.net                 |
|                                                           |
|-----------------------------------------------------------|
|   Syntax - html.pl "output file" "number of html files"   |
|                                                           |
|                [Usage: html.pl myfile 3]                  |
=============================================================
};
    exit;
}

#Take the arguments in the input command and define them as our variables to use
$filename = $ARGV[0];
$filecount = $ARGV[1];

#------------------------------------------------------------------------------------------
#Define a loop to loop through this script until we reach
#a $num that is equal to the one specified in the arguments
#--(This will loop through as long as the $num is less than and/or equal to $filecount)
#------------------------------------------------------------------------------------------
for ($num=1; $num <= $filecount; $num++) { #As long as $num is less than or equal to $filecount increment $num

    open(HTML, ">$filename$num.html"); #Open the file we're trying to write to

    if($num==$filecount) {
    $next = 1; #choose 1 as the number
    } else {
    $next = $num+1; #if 1 is taken then the add 1
    }

    #Here's where we add the information to the opened HTML file
    print HTML "<html>\n<head>\n<title>$filename$num</title>\n</head>\n<body>\n";
    print HTML "<a href=\"$filename$next.html\">Link to $filename$num</a>\n";
    print HTML "<p>Automatically Generated by HTML.pl - Created by Ace</p>\n";
    print HTML "</body>\n</html>\n";
    #We are finished with editing/creating this file
    close(HTML);
}
#(Onto the next file if $num has not reached $filecount
#Repeat until we hit the $filecount argument specified in the command

Here's my newest little script in perl. It's nothing really advaned, but it's quick for something simple. What this does is it will take parameters specified in the arguments of the command line for the script to determine html file creation requirements. These requirements include two variables that gets taken from the input command as an argument from the command line, such as a filename for the html's created, and a number of files to create with the html file extension.

Something like:
Code:
html.pl ace 3

Will tell the script to output 3 html files all linked to each other with the filename of ace and a filenumber before the file extension.

So it would output:
- ace1.html
- ace2.html
- ace3.html

And all are linked to each other.

I've commented out my entire script so that it's easy enough for you to follow along.

For use, the syntax stays the same as long as you have the pl file saved as html.pl on your local storage. Otherwise it would just be the name of the pl script followed by the last half of the syntax i've provided, which should be obvious.

If you save this script as htmlcreator.pl, then instead of the syntax being html.pl it would be htmlcreator.pl. Pretty simple.
Reply


Messages In This Thread
HTML perl script - by AceInfinity - 08-22-2011, 10:08 AM
RE: HTML perl script - by 0ld_F4T_N!gg4™ - 08-22-2011, 10:57 AM
RE: HTML perl script - by Hex - 11-07-2011, 07:49 PM
RE: HTML perl script - by New Jersey - 11-27-2011, 08:28 AM
RE: HTML perl script - by Jinu - 11-28-2011, 04:27 AM
RE: HTML perl script - by Closed Account - 12-03-2011, 11:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Compile Error in Perl liveproject101 0 1,303 04-12-2013, 03:08 AM
Last Post: liveproject101
  [Perl] IRC Bot wchar_t 26 14,617 08-20-2012, 01:40 PM
Last Post: Trump
  Perl Ebook ven0m 2 1,833 05-04-2012, 08:14 AM
Last Post: ven0m
  Help with a program written in perl Rodman42866 1 1,688 03-09-2012, 03:16 AM
Last Post: AceInfinity
  Perl ARGV Tutorial AceInfinity 0 2,404 08-22-2011, 02:30 PM
Last Post: AceInfinity

Forum Jump:


Users browsing this thread: 4 Guest(s)