Hi all, I am new to Perl, just learn this code in Essential Web Perl5 when i summit it it will write to 1.html, 2.html or number+.html but i would like to have it write to title.html so i can look it easier ex. Title 020212 file will save as 020212.html Thanks for your help
#!/usr/bin/perl5/perl &get_form_data; print "Content-type: text/html\n\n"; opendir(DIR, "./Data"); while($name = readdir(DIR)) { next if $name !~ /^\d*.html/; push(@files, $name); } close(DIR); if($#files == 0) { $nextfile = "1.html"; } else { $lastfile = $files[$#files]; $lastfile =~ s/.html//g; $nextfile = $lastfile + 1; $nextfile .= ".html"; } open(OUT, ">Data/$nextfile"); print OUT "<HTML>\n<HEAD>\n "; print OUT "<TITLE>\n"; print OUT "$FORM{'title'}\n"; print OUT "</TITLE>\n"; print OUT "</HEAD>\n"; print OUT "<BODY BGCOLOR=\"#FFFFFF\">\n"; print OUT "<CENTER><H1>\n"; print OUT "$FORM{'heading'}\n"; print OUT "</H1></CENTER><BR>\n"; print OUT "<P>\n"; print OUT "$FORM{'body'}\n"; close(OUT); push(@files, $nextfile); print "<HTML>\n<BODY>\n"; foreach $file (@files) { print "<A HREF=\"Data/$file\">$file</A>\n"; print "<BR>\n"; } print "</BODY>\n</HTML>\n"; exit; sub get_form_data { # Get the input read(STDIN, $buffer, $ENV{ 'CONTENT_LENGTH' } ); # Split the name-value pairs @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); # Un-Webify plus signs and %-encoding $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/\0//g; $value =~ s/<!--(.|\n)*-->//g; $value =~s/\cM//g; $value =~s/\n\n/<p>/g; $value =~s/\n/<br>/g; $FORM{ $name } = $value; } }

In reply to New and need help in cgi, perl by britney

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.