> Hello,
> 
> Can you guys tell me on this piece of codes? It doesn't print the small
> html codes in the sub below. No warning - nothing!
> N.B. Don't bother about the html; just check my perl codes to see why I
> doesn't print what I want.
> 
> Thanks
> 
> Babs 
> =============================================================
> #!/usr/bin/perl -w
> 
> 
> use strict;
> use File::Basename;
> 
> my ($filename, $dir, $ext,$picture,$images,$counter);

Declaring your variables like this at the top of the script generally
defeats the purpose of why you use 'my' to begin with. They are now
available anywhere in the rest of the file which will prevent Perl from
helping you. Better to only declare them when you need to, then let
scoping take over, and strict help you...

> $images ="watches";   
> opendir (IMGDIR, "$images") || die "\nCouldn't open directory ($images):
> $!\n";
> #while (defined($picture = readdir(IMGDIR))){
> 
> my @pictures = readdir(IMGDIR);

perldoc -f readdir

> foreach $picture (@pictures){
>               $counter = 0;   
>               if (-f $picture and $picture =~ /(\.gif|\.jpe?g)$/i){
>                       $counter++;
>                       ($filename, $dir, $ext) = fileparse($picture,
> '\..*');
>                               print "$picture,$filename";
>                               html_file($picture,$filename );
>                               
>               }       

You should, at least while debugging, provide an 'else' to the above
'if' to confirm that it is actually catching your picture.  $picture
doesn't exist because 'readdir' returns the filenames of the files in a
directory and you are not readdiring the cwd, so you need to prepend
'images' back onto the filename to test if it exists. You also don't
need to fileparse $picture to get $filename, not that you are, since the
'if' doesn't get entered.  I suspect that this will be your problem,
though I would avoid the here-doc altogether.

>               
> }
> closedir(IMGDIR);

The above can be moved up to after the 'foreach', unless you switch back
to your 'while'...

> 
> print "\n$counter templates printed successfully.";
> 
> ############################################################
> #  HTML Layout                   #
> ############################################################
> 
> sub html_file {
>       
>       my ($filename,$picture );
>       ($picture,$filename) = @_;

You can combine the above two lines.

my ($filename, $picture) = @_;

>    opendir (TMPLDIR, "Tmpl_out") || die "$!\n";  

You never read from this directory?

>    open (OUT, ">TMPLDIR/$filename.txt") || die "$!\n";   
> print OUT <<EOF;
>    <html><head><title>$filename</title></head>
>    <body><font face=" Arial, Times New Roman,Helvetica">
>    <p align="center">&nbsp;&nbsp;&nbsp;
>    <img src="$picture" border="1" color="#ffffff"></p>
>    <table><tr><td><table align="center">
>    <tr><td colspan="3" width="90%"
> align="center">&nbsp;</font></td></tr>
>    <tr bgcolor="#boc4de"><td colspan="3" >
>    </td></tr><tr><td height="200">
>    <img src="$picture"></td><td height="200">
>    <img src="$picture"></td></tr></table>
> EOF
> close (OUT);
> closedir (TMPLDIR);
> }
> 

HTH,

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to