Support Forums
HTML perl script - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Perl Programming Support (https://www.supportforums.net/forumdisplay.php?fid=31)
+---- Thread: HTML perl script (/showthread.php?tid=21642)



HTML perl script - AceInfinity - 08-22-2011

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.


RE: HTML perl script - 0ld_F4T_N!gg4™ - 08-22-2011

Thanks for the great script Ace. Always HQ and helpful. Big Grin


RE: HTML perl script - Hex - 11-07-2011

Thank you for the awesome script im going to try that in 2 mins!


RE: HTML perl script - New Jersey - 11-27-2011

Thanks for the script man. <3     


RE: HTML perl script - Jinu - 11-28-2011

nice!! thank you for this script dude!!


RE: HTML perl script - Closed Account - 12-03-2011

Seems like A awesome script im
Going to try it out.