Hi All,

playing with this basic script,

#!/usr/bin/perl use strict; use warnings; use File::Find; my $dir = shift; find(\&print_name_if_file, "$dir"); sub print_name_if_file { print "$_\n" if -f; }

and was wondering why the files are printed out of order? I know of the sort utility, but, why doesn't it print the same order as a normal ls -al does? Cheers.

Perl output

[racket@ibmlap perl]$ ./filechng.pl testdir file4.pdf file5.pdf file2.pdf file3.pdf file10.pdf file7.pdf file9.pdf file8.pdf file1.pdf file6.pdf

Here is the ls -al output

[racket@ibmlap perl]$ ls -al testdir total 56 drwxrwxr-x 2 racket racket 4096 Mar 24 14:59 . drwxrwxr-x 3 racket racket 4096 Mar 24 15:08 .. -rw-rw-r-- 1 racket racket 0 Mar 24 14:59 file10.pdf -rw-rw-r-- 1 racket racket 0 Mar 24 14:58 file1.pdf -rw-rw-r-- 1 racket racket 0 Mar 24 14:58 file2.pdf -rw-rw-r-- 1 racket racket 0 Mar 24 14:58 file3.pdf -rw-rw-r-- 1 racket racket 0 Mar 24 14:58 file4.pdf -rw-rw-r-- 1 racket racket 0 Mar 24 14:59 file5.pdf -rw-rw-r-- 1 racket racket 0 Mar 24 14:59 file6.pdf -rw-rw-r-- 1 racket racket 0 Mar 24 14:59 file7.pdf -rw-rw-r-- 1 racket racket 0 Mar 24 14:59 file8.pdf -rw-rw-r-- 1 racket racket 0 Mar 24 14:59 file9.pdf

Cheers.

coolboarderguy...


In reply to Files Print Out Of Order by coolboarderguy

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.