dhaval0203 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, i want to split a html file into given number of parts,how to do it? each part must be end with html tag and output store in separate file.

The html file is given below, i want to split it in 10 parts and then same file i want to split it in 5 parts how to do it? each file must be end with any tag.please give me code.

<html xmlns="http://www.w3.org/TR/REC-html40" xmlns:v="urn:schemas-mic +rosoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-12 +52"> <LINK REL="SHORTCUT ICON" HREF="http://techpreparation.com/images/favi +con.ico"> <title>PERL Interview Questions Answers</title> <link rel="stylesheet" type="text/css" href="../templates/new_designs_ +template/site-designs/index-styles.css"> <link rel="stylesheet" type="text/css" href="../site-designs/new_templ +ate1.css"> <style type="text/css"></style> </head> <body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" ma +rginheight="0" marginwidth="0" style="background-color: #FFFFFF"> <table border="0" width="100%" cellspacing="0" cellpadding="0" class=" +style30"> <tr> <td style="width: 23%"> <a href="http://techpreparation.com"> <img alt="techpreparation-homepage" src="../images/techpreparation-hom +epage.jpg" width="237" height="44" class="style52"></a></td> <td width="50%" valign="bottom" class="style6"> </td> </tr> </table> <table border="0" cellspacing="0" cellpadding="0" class="test1" style= +"height: 22px; width: 100%"> <tr> <td width="99%" class="style46"> <!--webbot bot="Include" U-Include="../site-designs/top-menu.htm" TAG= +"BODY" startspan --> <table border="0" cellspacing="0" cellpadding="0" class="test1" style= +"height: 22px; width: 100%"> <tr> <td width="99%" class="style46"> <p class="style6"> <a href="http://techpreparation.com/" class="navigation-top"><strong>H +ome</strong></a>&nbsp; <strong><a class="navigation-top" href="../interview-questions.htm">In +terview Questions</a></strong>&nbsp; <strong><a class="navigation-top" href="../aptitude-questions.htm">Apt +itude Questions</a></strong>&nbsp; <strong><a class="navigation-top" href="../tutorials.htm">Tutorials</a +></strong>&nbsp; <strong><a class="navigation-top" href="../placement-papers.htm">Place +ment Papers</a></strong>&nbsp; <strong> <a class="navigation-top" href="../search.htm">Search</a></strong>&nbs +p; <strong><a class="navigation-top" href="../resume-guide.htm">Resume Gu +ide</a></strong>&nbsp; <strong> <a class="navigation-top" href="../soft-skills.htm">Soft Skills</a></s +trong>&nbsp; <strong> <a class="navigation-top" href="../video.htm">Video</a></strong>&nbsp; <a href="http://techpreparation.com/post/" class="navigation-top"> <strong>Forum</strong></a>&nbsp; <a class="navigation-top" href="http://techpreparation.com/blog/"><str +ong>Blog</strong></a></td> </tr> </table> <!--webbot bot="Include" i-checksum="21456" endspan --></td> </tr> </table> <table style="width: 100%" class="style47" cellspacing="0" cellpadding +="0" align="center"> <tr> <td class="style48" style="width: 218px" valign="top"> <p> <span class="index-headin"><br>Technical Interview Questions<br> </span> <a class="sub-index-color" href="../python-interview-questions-answers +1.htm"> Python Interview Questions</a><br> <a class="sub-index-color" href="../cpp-interview-question-answer1.htm +"> C++ Interview Questions</a><br> <a class="sub-index-color" href="../php-interview-questions-answers1.h +tm"> Php Interview Questions</a><br> <a class="sub-index-color" href="../xml-interview-questions-answers1.h +tm"> Xml Interview Questions</a><br> <a class="sub-index-color" href="../c-interview-questions-answers1.htm +">C Interview Questions</a><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs +p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& +nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a class="sub-index-color" href="../interview-questions.htm">......... +More</a></span><p> <span class="index-headin">Soft Skills</span><br> <a href="../soft-skills/communication.htm" class="sub-index-color"> Communication Skills</a><br> <a href="../soft-skills/leadership-skills.htm" class="sub-index-color" +> Leadership Skills</a><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs +p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& +nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <a href="../soft-skills.htm" class="sub-index-color">.........More</a> +</span></p> <form method="post" action="http://www.aweber.com/scripts/addlead.pl" +target="_new"> <input type="hidden" name="meta_web_form_id" value="1470006299"> <input type="hidden" name="meta_split_id" value=""> <input type="hidden" name="unit" value="techpreparation"> <input type="hidden" name="redirect" value="http://techpreparation.com +/thanks.html"> <input type="hidden" name="meta_redirect_onlist" value=""> <input type="hidden" name="meta_adtracking" value="Interview "> <input type="hidden" name="meta_message" value="1"> <input type="hidden" name="meta_required" value="from"> <input type="hidden" name="meta_forward_vars" value="0"> <table> <tr><td colspan=2> <span class="index-headin">Subscribe to our Newsletters</span></td></tr> <tr><td><span class="index-headin">Name:</span></td><td style="width: +170px"> <input type="text" name="name" value="" size="20" style="width: 165px" +></td></tr> <tr><td><span class="index-headin">Email:</span></td><td style="width: + 170px"> <input type="text" name="from" value="" size="20" style="width: 164px" +></td></tr> <tr><td align="center" colspan="2"><input type="submit" name="submit" +value="Join Now!"></td></tr> </table> </form> <p class="style6"> <script type="text/javascript">addthis_pub = 'leopez';</script> <a href="http://www.addthis.com/bookmark.php" onmouseover="return addt +his_open(this, '', '[URL]', '[TITLE]')" onmouseout="addthis_close()" +onclick="return addthis_sendto()"><img src="http://s9.addthis.com/but +ton1-bm.gif" width="125" height="16" border="0" alt="" /></a><script +type="text/javascript" src="http://s7.addthis.com/js/152/addthis_widg +et.js"></script> </p> <p> &nbsp;</p> </td> <td class="style50" style="width: 4px">&nbsp;</td> <td class="style49" valign="top"> <p class="style6"> <center> <form method="get" action="http://techpreparation.com/search2.htm" tar +get="_top"> <table bgcolor="#add7f7"> <tr><td nowrap="nowrap" valign="top" align="left" height="32"> &nbsp;<input type="text" name="q" size="41" maxlength="255" value="" i +d="sbi"></input>&nbsp; <input type="submit" name="sa" value="Google Search" id="sbb"></input> + <input type="hidden" name="client" value="pub-7003540323320880"></inpu +t> <input type="hidden" name="forid" value="1"></input> <input type="hidden" name="channel" value="3422992112"></input> <input type="hidden" name="ie" value="ISO-8859-1"></input> <input type="hidden" name="oe" value="ISO-8859-1"></input> <input type="hidden" name="safe" value="active"></input> <input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#336699;V +LC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000 +000;GFNT:0000FF;GIMP:0000FF;FORID:11"></input> <input type="hidden" name="hl" value="en"></input> </td></tr></table> </form> </center> <table cellpadding="0" cellspacing="0" class="for_ads"> <tr> <td><script type="text/javascript"><!-- google_ad_client = "pub-7003540323320880"; google_ad_width = 336; google_ad_height = 280; google_ad_format = "336x280_as"; google_ad_type = "text"; google_ad_channel = "5181050807"; google_color_border = "FFFFFF"; google_color_bg = "FFFFFF"; google_color_link = "0000FF"; google_color_text = "000000"; google_color_url = "191919"; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </td> </tr> </table> <h1><span class="interview-heading">Perl Interview Questions and Answe +rs</span></h1> <p class="answers"> <b><span class="for_questions_blue">How to read from a pipeline with P +erl</span><span class="answers"><br> </span></b>Example 1: <br> <br> To run the date command from a Perl program, and read the output<br> of the command, all you need are a few lines of code like this: <br> <br> open(DATE, &quot;date|&quot;); <br> $theDate = &lt;DATE&gt;; <br> close(DATE); <br> <br> The open() function runs the external date command, then opens <br> a file handle DATE to the output of the date command. <br> <br> Next, the output of the date command is read into <br> the variable $theDate through the file handle DATE.<br> <br> Example 2:<br> <br> The following code runs the &quot;ps -f&quot; command, and reads the output:<br> <br> open(PS_F, &quot;ps -f|&quot;); <br> while (&lt;PS_F&gt;) { <br> ($uid,$pid,$ppid,$restOfLine) = split; <br> # do whatever I want with the variables here ... <br> } <br> close(PS_F); </p> <p class="answers"><b class="for_questions_blue">Why is it hard to cal +l this function: sub y { &quot;because&quot; } </b> <br> Because y is a kind of quoting operator.<br> The y/// operator is the sed-savvy synonym for tr///. That means y(3) would be like tr(), which would be looking for a second string, as in tr/a-z/A-Z/, tr(a-z)(A-Z), or tr[a-z][A-Z].</p> <p class="answers"><b class="for_questions_blue">What does `$result = +f() .. g()' really return? </b><br> False so long as f() returns false, after which it returns true until g() returns true, and then starts the cycle again.<br> This is scalar not list context, so we have the bistable flip-flop range operator famous in parsing of mail messages, as in `$in_body = /^$/ .. eof()'. Except for the first time f() returns true, g() is entirely ignored, and f() will be ignored while g() later when g() is evaluated. Double dot is the inclusive range operator, f() and g() will both be evaluated on the same record. If you don't want that to happen, the exclusive range operator, triple dots, can be used instead. For extra credit, describe this:<br> $bingo = ( a() .. b() ) ... ( c() .. d() ); </p> <p class="answers"><b class="for_questions_blue">Why does Perl not hav +e overloaded functions? </b> <br> Because you can inspect the argument count, return context, and object types all by yourself.<br> In Perl, the number of arguments is trivially available to a function via the scalar sense of @_, the return context via wantarray(), and the types of the arguments via ref() if they're references and simple pattern matching like /^\d+$/ otherwise. In languages like C++ where you can't do this, you simply must resort to overloading of functions. </p> <p class="answers"><b class="for_questions_blue">What does read() retu +rn at end of file? </b> <br> 0<br> A defined (but false) 0 value is the proper indication of the end of file for read() and sysread(). <br> </p> <p class="answers"><b class="for_questions_blue">What does `new $cur-& +gt;{LINK}' do? (Assume the current package has no new() function of its own.) </b> <br> $cur-&gt;new()-&gt;{LINK}<br> The indirect object syntax only has a single token lookahead. That means if new() is a method, it only grabs the very next token, not the entire following expression.<br> This is why `new $obj[23] arg' does't work, as well as why `print $fh[23] &quot;stuff\n&quot;' does't work. Mixing notations between the OO and IO notations is perilous. If you always use arrow syntax for method calls, and nothing else, you'll not be surprised. <br> </p> <p class="answers"><b><span class="for_questions_blue">How do I sort a + hash by the hash value? </span> </b><br> Here's a program that prints the contents <br> of the grades hash, sorted numerically by the hash value:<br> <br> #!/usr/bin/perl -w<br> <br> # Help sort a hash by the hash 'value', not the 'key'. <br> to highest).<br> sub hashValueAscendingNum {<br> $grades{$a} &lt;=&gt; $grades{$b};<br> }<br> <br> <br> <br> # Help sort a hash by the hash 'value', not the 'key'. <br> # Values are returned in descending numeric order <br> # (highest to lowest).<br> sub hashValueDescendingNum {<br> $grades{$b} &lt;=&gt; $grades{$a};<br> }<br> <br> <br> %grades = (<br> student1 =&gt; 90,<br> student2 =&gt; 75,<br> student3 =&gt; 96,<br> student4 =&gt; 55,<br> student5 =&gt; 76,<br> );<br> <br> print &quot;\n\tGRADES IN ASCENDING NUMERIC ORDER:\n&quot;;<br> foreach $key (sort hashValueAscendingNum (keys(%grades))) {<br> print &quot;\t\t$grades{$key} \t\t $key\n&quot;;<br> }<br> <br> print &quot;\n\tGRADES IN DESCENDING NUMERIC ORDER:\n&quot;;<br> foreach $key (sort hashValueDescendingNum (keys(%grades))) {<br> print &quot;\t\t$grades{$key} \t\t $key\n&quot;;<br> }</p> <p class="answers"><span style="font-weight: 400"><font size="3"> <span class="answers">Page Numbers :&nbsp;&nbsp;&nbsp; <a href="../perl-interview-questions-answers1.htm"> 1</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <a href="../computer-interview-questions/perl-interview-questions-answ +ers2.htm"> 2</a>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <a href="../computer-interview-questions/perl-interview-questions-answ +ers4.htm"> 4</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <a href="../computer-interview-questions/perl-interview-questions-answ +ers5.htm"> 5</a></span></font></span></p> <script type="text/javascript">addthis_pub = 'leopez';</script> <a href="http://www.addthis.com/bookmark.php" onmouseover="return addt +his_open(this, '', '[URL]', '[TITLE]')" onmouseout="addthis_close()" +onclick="return addthis_sendto()"><img src="http://s9.addthis.com/but +ton1-bm.gif" width="125" height="16" border="0" alt="" /></a><script +type="text/javascript" src="http://s7.addthis.com/js/152/addthis_widg +et.js"></script> <p><span class="bottom-navigation">Have a Question ? <a href="http://techpreparation.com/post/">post your questions</a> her +e. It will be answered as soon as possible.</span></p> <p><span class="bottom-navigation">Check <a href="../html-interview-questions-answers1.htm">HTML Interview Questions</a> for more HTML Interview Questions with Answers</p> <p><span class="bottom-navigation">Check <a href="../interview-questions.htm">Job Interview Questions</a> for more Interview Questions with Answers</p> <p>&nbsp;</p> </td> </tr> </table> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ss +l." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analyti +cs.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> var pageTracker = _gat._getTracker("UA-1832638-3"); pageTracker._initData(); pageTracker._trackPageview(); </script> <!--webbot bot="Include" U-Include="../site-designs/bottom-menu2.htm" +TAG="BODY" startspan --> <p> </p> <!--webbot bot="Include" i-checksum="2800" endspan --> </body> </html> <!-- text below generated by server. PLEASE REMOVE --><!-- Counter/Sta +tistics data collection code --><script language="JavaScript" src="ht +tp://us.js2.yimg.com/us.js.yimg.com/lib/smb/js/hosting/cp/js_source/w +hv2_001.js"></script><script language="javascript">geovisit();</scrip +t><noscript><img src="http://visit.webhosting.yahoo.com/visit.gif?us1 +275630738" alt="setstats" border="0" width="1" height="1"></noscript>

Thank You....

Replies are listed 'Best First'.
Re: how to split a html file?
by marto (Cardinal) on Jun 03, 2010 at 07:21 UTC

    Use a module such as HTML::TokeParser::Simple to parse your HTML input and split it into sensible chunks, assuming you have start and end points on which to split the file. Populate each resultant HTML file perhaps using something like HTML::Template to make this easier for you.

    Update: Reworded last sentence.

    Update: I notice you've posted the HTML page in question, ignoring the sites post formatting guidelines and you've not marked your post as having been updated. See How do I post a question effectively? for details. Perhaps you should make "split a html file into given number of parts,how to do it? each part must be end with html tag and output store in separate file." one of your interview questions ;) This isn't rent a coder or a code writing service. Read the advice I've given, write some code and try it. If you have problems come back and show us your attempt.

    Update: I see you made similar 'effort' when posting how to split html file?

Re: how to split a html file?
by ww (Archbishop) on Jun 05, 2010 at 12:33 UTC
    "please give me code."

    Paraphrased:

    "please give me fish."

    ...and if I do, you'll be hungry again tomorrow.

    Take marto's advice instead; this site is here to help you learn; it's not code-a-matic.