Greets, Having a little trouble....I'm creating a directory structure tree that is output to html. When I use -w on the she-bang line I continually get the message...."Use of uninitialized value in print.....use of uninitialized value in numeric le (<=) at line....." I'm essentially running a filetest to check the modification age of the document stored in the search dir, yet all of my output states the files are "brandnew". This is very bewildering to me. Can anyone take a look at this code and help me out? (I won't bother including the myhtml.pm code used, since that functions properly)
#!/usr/bin/perl -w use myhtml; use strict; print"Please enter the directory to be searched. "; chomp(my $dirname = <STDIN>); until(-d $dirname){ print"The directory entered is not valid.\nPlease enter a director +y to be searched. "; chomp($dirname = <STDIN>); } unless($dirname =~ /\\$/){ $dirname .= "\\"; } open OUT, ">dir_stuff.html" || die "Could not open file: !, $!"; my $beginning = &myhtml::start_doc($dirname); print OUT <<MYHTML; $beginning MYHTML print OUT "$dirname<br>\n"; &search($dirname, 0); my $ending = &myhtml::end_doc(); print OUT <<MYHTML; $ending MYHTML sub search(){ my($dir, $offset) = @_; my $fullname; opendir DIR, $dir; foreach my $file(readdir DIR){ next if ($file =~ /^\./); if($file =~ /\.pl$/){ $fullname = $dir . $file . "\\"; &printFile($file, $offset, $fullname, 0); } if($file =~ /\.html$/){ $fullname = $dir . $file. "\\"; &printFile($file, $offset, $fullname, 1); } if(-d $dir.$file){ &printFile($file, $offset, $fullname, 2); $fullname = $dir . $file. "\\"; &search($fullname, $offset + 1); } } } sub printFile(){ my @file_type = qw(perl html dir); my @file_color = qw(orange red green); my($file, $offset, $filename, $type) = @_; my $spacer; my $age; my $days_old = (-M $filename.$file); if($offset > 0){ $spacer ="|" . "&nbsp;" x (4 * $offset); } if ( $days_old <= 7 ){ $age = "<b><i>brand</i>new!</b>"; }elsif ( $days_old < 30 ){ $age = "<b>new!</b>"; }else{ $age = "";} print OUT $days_old; print OUT "$spacer|----<font color= $file_color[$type]>$file_type[ +$type]: $file</font> $age<br>\n"; }
The html file created looks correct except the modification stamp isn't accurate for the files. Thanks in advance....

In reply to File Test help with -M (modification age) by psychoto

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.