Don't forget the usefulness of interpolated heredocs '<<' in generating html. See heredocs
#!/usr/bin/perl use warnings; use strict; #this one accounts for pics with no text file umask 0022; #do a simple glob for .txt files my @tfiles = <*.txt>; (@tfiles) = map{ $_ =~ /(.*).txt$/ } @tfiles; print "text-> @tfiles\n"; #assume photos are in subdir pics/* #do a simple glob for .jpg files my @jfiles = <pics/*.jpg>; (@jfiles) = map{ $_ =~ /pics\/(.*).jpg$/ } @jfiles; print "jpg-> @jfiles\n"; #now find which pics don't have a txt file my %h; # Initialise the hash using a slice @h{@tfiles} = undef; @jfiles = grep {not exists $h{$_}} @jfiles; print "stray jpg-> @jfiles\n"; #now push the stray photo onto the end of the @tfiles push @tfiles,@jfiles; print "all html-> @tfiles\n"; foreach my $file (@tfiles) { open(HH, "> $file.html") or warn "$!\n"; my $text = ''; #print headline print HH<<EOH; <html> <BODY TEXT="#FFCCCC" BGCOLOR="#000000"> <center><h1>$file</h1></center> EOH #print jpg if exists if( -e "pics/$file.jpg"){ print HH<<EOI; <center><IMG SRC="pics/$file.jpg" alt="[$file.jpg]"></center> EOI }else{ print HH<<EOI; <center><IMG SRC="" alt="[No Image Available]"></center> EOI } #print text if exists if( -e "$file.txt"){ open(TH, "< $file.txt") or warn "$!\n"; read( TH, $text, -s TH ); close TH; print HH<<EOT; <center> <pre> $text </pre> </center> EOT } print HH<<EOHTML; </body> </html> EOHTML close HH; }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: write html code with perl by zentara
in thread write html code with perl by lenieto3

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.