Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > -d file test using Active State PERL under Windows

Reply
Thread Tools

-d file test using Active State PERL under Windows

 
 
Scott
Guest
Posts: n/a
 
      10-06-2004
Hi,

I have this test script:

my $dir = "C:/WINNT";
opendir(DIR,$dir) || die("Cannot open directory $dir");
my @files = readdir DIR;
closedir(DIR);

foreach (@files) {
print "$_\n" if -d; # -d -f -t -T -B
}

I've cycled thru the tests as per the comment line above.

Here is the (annotated) output:

C:\Perl\my.scripts>test2 (-d)
..
...

C:\Perl\my.scripts>test2 (-f)

C:\Perl\my.scripts>test2 (-t a bit nonsensical to try but...)
..
...
$NtUninstallKB329115$
$NtUninstallKB820888$
$NtUninstallKB822831$
$NtUninstallKB823182$
$NtUninstallKB824105$
$NtUninstallKB825119$
$NtUninstallKB826232$
$NtUninstallKB828749$
$NtUninstallKB837272$
$NtUninstallKB839643-DirectX9$
$NtUninstallKB839645$
$NtUninstallKB840315$
$NtUninstallKB841872$
$NtUninstallKB841873$
$NtUninstallKB842526$
$NtUninstallQ818043$
$NtUninstallQ828026$
Active Setup Log.txt
(rest deleted)

C:\Perl\my.scripts>test2 (-T)

C:\Perl\my.scripts>test2 (-B)

C:\Perl\my.scripts>

For -d, I would have expected it to list all the directories (only) under
C:\WINNT.
For -f, I would have expected it to list all the plain files (i.e.
everything except directories)
For -t, I'm not sure what it should have listed. The doc says "-t
Filehandle is opened to a tty."
For -T, I would have expected it to list all the ASCII text files.
For -B, I would have expected it to list all the binary files.

Any idea what I might be doing wrong? Are my assumptions incorrect?

In my actual script, I have to read a directory, and process only the
returned directories in that directory. I'm running ActiveState PERL under
Windows 2000 Professional.

Here is the version of PERL I'm using:

C:\Perl\my.scripts>perl -V
Summary of my perl5 (revision 5 version 8 subversion 3) configuration:
Platform:
osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
uname=''
config_args='undef'
hint=recommended, useposix=true, d_sigaction=undef
usethreads=undef use5005threads=undef useithreads=define
usemultiplicity=define
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cl', ccflags
='-nologo -Gf -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT
-DNO_HASH_SEED -DPERL_IMPLICIT_CONTEXT -DPERL_IMPL
ICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX',
optimize='-MD -Zi -DNDEBUG -O1',
cppflags='-DWIN32'
ccversion='', gccversion='', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64',
lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='link', ldflags
'-nologo -nodefaultlib -debug -opt:ref,icf -libpath:"C:\Perl\lib\CORE" -machine86'
libpth=C:\PROGRA~1\MICROS~3\VC98\lib
libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib
uuid.lib wsoc
k32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib
perllibs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib
uuid.lib
wsock32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib
msvcrt.lib
libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib
gnulibc_version='undef'
Dynamic Linking:
dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ',
lddlflags='-dll -nologo -nodefaultlib -debug -opt:ref,icf -libpath:"C:\Perl\lib\CORE"
-machine86'


Characteristics of this binary (from libperl):
Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES
PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS
Locally applied patches:
ActivePerl Build 809
22218 Remove the caveat about detached threads crashing on Windows
22201 Avoid threads+win32 crash by freeing Perl interpreter slightly
later
22169 Display 'out of memeory' errors using low-level I/O
22159 Upgrade to Time::Hires 1.55
22120 Make 'Configure -Dcf_by=...' work
22051 Upgrade to Time::HiRes 1.54
21540 Fix backward-compatibility issues in if.pm
Built under MSWin32
Compiled at Feb 3 2004 00:28:51
@INC:
C:/Perl/lib
C:/Perl/site/lib
 
Reply With Quote
 
 
 
 
Rhesa Rozendaal
Guest
Posts: n/a
 
      10-07-2004
Scott wrote:
> Hi,
>
> I have this test script:
>
> my $dir = "C:/WINNT";
> opendir(DIR,$dir) || die("Cannot open directory $dir");
> my @files = readdir DIR;
> closedir(DIR);
>
> foreach (@files) {
> print "$_\n" if -d; # -d -f -t -T -B
> }
>


> C:\Perl\my.scripts>test2 (-d)


[snip]

> Any idea what I might be doing wrong? Are my assumptions incorrect?


Yes, your assumption about the current working directory.
Next time, try

print $_,$/ if -d "$dir/$_";


HTH,

Rhesa
 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      10-07-2004
Scott <> wrote:

> I have this test script:
>
> my $dir = "C:/WINNT";
> opendir(DIR,$dir) || die("Cannot open directory $dir");
> my @files = readdir DIR;
> closedir(DIR);
>
> foreach (@files) {
> print "$_\n" if -d; # -d -f -t -T -B
> }



> I've cycled thru the tests as per the comment line above.



How many minutes have you spent troubleshooting this problem so far?

10 minutes perhaps?


> For -d, I would have expected it to list all the directories (only) under

^^^^^^^^^^^^^^^^^^^^^
> C:\WINNT.



What info did you base that expectation on?

Did you try reading the documentation for the functions you are using?

They warn you away from the very problem you are having.


> Any idea what I might be doing wrong?



Not reading the documentation for the functions you are using.


> Are my assumptions incorrect?



perldoc -f readdir

(the second paragraph

If you're planning to filetest the return values out of a
"readdir", you'd better prepend the directory in question.
Otherwise, because we didn't "chdir" there, it would have been
testing the wrong file.


How many minutes would it have taken to read 2 short paragraphs?

Less than one perhaps?


Work smart, use the docs Luke.





[ snip long version output ]

We almost never need that info as the bug is most often in the
programmer's program than a bug in perl itself.

We almost always need Real Perl Code to help solve the problem though,
so please include Perl code when you have another question.

Have you seen the Posting Guidelines that are posted here frequently?


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Scott
Guest
Posts: n/a
 
      10-07-2004
Duh, don't I feel like an idiot! Yes, the full path to the file test would
be useful!

Thanks Rhesa, much appreciated!

"Rhesa Rozendaal" <perl&(E-Mail Removed)> wrote in message
news:41648dcf$0$78738$(E-Mail Removed)4all.nl...
> Scott wrote:
>> Hi,
>>
>> I have this test script:
>>
>> my $dir = "C:/WINNT";
>> opendir(DIR,$dir) || die("Cannot open directory $dir");
>> my @files = readdir DIR;
>> closedir(DIR);
>>
>> foreach (@files) {
>> print "$_\n" if -d; # -d -f -t -T -B
>> }
>>

>
>> C:\Perl\my.scripts>test2 (-d)

>
> [snip]
>
>> Any idea what I might be doing wrong? Are my assumptions incorrect?

>
> Yes, your assumption about the current working directory.
> Next time, try
>
> print $_,$/ if -d "$dir/$_";
>
>
> HTH,
>
> Rhesa



 
Reply With Quote
 
Michele Dondi
Guest
Posts: n/a
 
      10-07-2004
On Thu, 7 Oct 2004 09:58:35 +1000, "Scott" <usenet739_yahoo_com_au>
wrote:

>I have this test script:
>
>my $dir = "C:/WINNT";
>opendir(DIR,$dir) || die("Cannot open directory $dir");


BTW: it may be sensible to include $! in the die() message. Also, I
*like* to put a \n at the end of it, but then often I get slapped for
it seems that people here have a tendency to prefer the more verbose
info given by the form you use yourself.

>my @files = readdir DIR;
>closedir(DIR);
>
>foreach (@files) {
> print "$_\n" if -d; # -d -f -t -T -B
>}


As a side note you may be interested to know that this test script is
ridiculously verbose for what it does. If it's just a minimal example
of something else, then just fine! But to give you an idea, simple
one-liners like

perl -le "print for grep -d, <*>"

or

perl -le "-d and print for <*>"

would just do (almost) what your script does.


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PERL can't open file for logging (world writable directory Windows XP Home/ Active Perl / Apache) PGPS Perl Misc 10 11-14-2006 01:40 AM
IIS Like Error using Perl Active State w/ SQL Server or MySQL jr_dunson@yahoo.com Perl Misc 3 04-28-2006 09:53 PM
Compiling Perl to exe with Active State Perl Maciej Kozinski Perl 0 11-28-2003 11:48 AM
Active State Komodo for Perl - anyone using? CaptainMcBunnyTickle Perl 0 09-21-2003 12:08 PM
test test test test test test test Computer Support 2 07-02-2003 06:02 PM



Advertisments