Shishir Saxena wrote:
> 
> Hi,

Hello,

> I'm doing the following and the purpose is to genrate a HTML log file. But
> the script says "Can not apply stat : No such file or directory found"
> Can someone plz tell me where I'm going wrong ?

use warnings;
use strict;

> use File::Find;
> use File::stat;
> 
> open (OUT,">./out.html");

You should _ALWAYS_ verify that the file opened correctly.

open (OUT,">./out.html") or die "Cannot open out.html: $!";


> $Root = $ARGV[0];
> print $Root;
> 
> my $var;
> 
> print OUT '<html>
> 
> <head>
> <meta http-equiv="Content-Language" content="en-us">
> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
> <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
> <meta name="ProgId" content="FrontPage.Editor.Document">
> <title>Path of File</title>
> </head>
> 
> <body>
> 
> <table border="1" width="106%">
>   <tr>
>     <td width="20%" align="center" bgcolor="#CCCC00"><b>Path of
> File</b></td>
>     <td width="20%" align="center" bgcolor="#CCCC00"><b>File
> Version</b></td>
>     <td width="20%" align="center" bgcolor="#CCCC00"><b>Build
> Number</b></td>
>     <td width="20%" align="center" bgcolor="#CCCC00"><b>Size on
> Disk</b></td>
>     <td width="20%" align="center" bgcolor="#CCCC00"><b>Timestamp</b></td>
>   </tr>';
> 
>     find (\&wanted,"$Root");

You don't need to enclose scalar variables in quotes, $Root is already a
string.

      find( \&wanted, $Root );


> print OUT '  </table>
> <p>&nbsp;</p>
> 
> </body>
> 
> </html>';
> 
> sub wanted()
            ^^
Why are you using a prototype here?


> {
>    if (-d $File::Find::name)
>    {
>     return;
>     }
>    $file = $File::Find::name;
>    $file =~ s/\//\\/g;

You are changing all the slashes to backslashes so of course stat can't
find the file.


>    $st = stat($file);
>    $size = $st->size;
>    $size = ($size/1024)."KB ($size bytes)";
>    $time = scalar localtime $st->mtime;

If you remove the "use File::stat;" line at the top you can do what you
want like this:

sub wanted {
    my $time = scalar localtime ( stat )[ 9 ];
    return if -d _;
    my $size = -s _;
    $size = ( $size / 1024 ) . "KB ($size bytes)";
    my $file = $File::Find::name;


>                     print OUT '
>                       <tr>
>     <td width="20%" align="center" bgcolor="#FFFFCC">'."$file".'</td>
>     <td width="20%" align="center" bgcolor="#FFFFCC">Not Available</td>
>     <td width="20%" align="center" bgcolor="#FFFFCC">Not Available</td>
>     <td width="20%" align="center" bgcolor="#FFFFCC">'."$size".'</td>
>     <td width="20%" align="center" bgcolor="#FFFFCC">'."$time".'</td>
>     </tr>';


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to