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
#2
Thanks for the great script Ace. Always HQ and helpful. Big Grin

[Image: tumblr_l1q0cxbD0h1qzjz68o1_250.gif]

Reply
#3
Thank you for the awesome script im going to try that in 2 mins!
Reply
#4
Thanks for the script man. <3     
Reply
#5
nice!! thank you for this script dude!!
[Image: 6c221674de.png]
Reply
#6
Seems like A awesome script im
Going to try it out.
Reply


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

Forum Jump:


Users browsing this thread: 1 Guest(s)