in reply to differences in dir?

Because the second command creates (or modifies) a file within the current directory. Ie. dir.txt.

BTW. Depending what you want to do with it, this is probably a really bad way to get a list of files.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: differences in dir?
by Anonymous Monk on May 02, 2007 at 16:59 UTC
    @dirA is just a list, it doesn't contain date, time and size like @dirB does.

    I think perhaps you didn't read a key part of the problem description.

      Hmm. I tried it (on XP), and I get exactly the same output, including data and time, in the file as I get to the screen:

      [0] Perl> `dir >junk.txt`;; [0] Perl> @d2 = do{ local @ARGV = 'junk.txt'; <> };; [0] Perl> print for @d2[ 0 .. 10 ];; Volume in drive C has no label. Volume Serial Number is BCCA-B4CC Directory of c:\test 2007-05-02 16:31 <DIR> . 2007-05-02 16:31 <DIR> .. 2005-06-24 13:45 721 12balls.pl 2005-11-12 16:16 1,142 12days-enc.pl 2005-11-13 02:26 1,688 12days.pl 2004-07-28 00:37 124,592,128 1Mx4096.db

      As far as I am aware, the only way to get a raw list of files without the data and time is to use the /b switch on the dir command:

      [0] Perl> `dir /b >junk.txt`;; [0] Perl> @d2 = do{ local @ARGV = 'junk.txt'; <> };; [0] Perl> print for @d2[ 0 .. 10 ];; 12balls.pl 12days-enc.pl 12days.pl 1Mx4096.db 2.log 200083.pl 216398.pl 250802.pl 275606.pl 27x2.wav 282393.pl

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        As far as I am aware, the only way to get a raw list of files

        I guess you didn't consider the alternative that the poster might "have a 'dir' program in [their] $ENV{PATH}". (:

        One of my copies of cygwin has "dir.exe", one of them doesn't. Cygwin dir.exe appears to (by default) just list filenames, somewhat like 'ls'.

        - tye