Howdy all...it's me and my next beginner's problem. So far I have written the following code. It's pretty obvious what it does (at the moment anyway). What I'm having troubles with is getting the directories to print out before the files. The order in which they appear in my while loop doesn't seem to matter which seems kinda weird to me.

Eventually all of it will need to get printed out to a file, but I'll cross that bridge soon (who knows...how I've written this script so far may have pre-burnt that bridge? lemme know please). Also, I'm trying to do this one without using the DirHandle module.
#!usr/bin/perl use warnings; use strict; my $dir = "/Users/ctp/perlwork"; opendir (DIRHANDLE, $dir) or die "can't open $dir: $!"; print "<HTML>\n<HEAD></HEAD>\n<BODY>\n"; while ( defined (my $file = readdir DIRHANDLE)) { next if $file =~ /^\.\.?$/; print "<B>$file</B><BR>\n" if -d "$dir/$file"; print "$file<BR>\n" if -T "$dir/$file"; } closedir (DIRHANDLE); print "</BODY>\n</HTML>\n";
As always - many thanks in advance!

ps - I'm using strict all the time now...see, I told you I'd get there ;-)

In reply to reading files and directories by ctp

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.