delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/06/23/04:49:46

X-Spam-Check-By: sourceware.org
Date: Sat, 23 Jun 2007 04:49:27 -0400 (EDT)
From: William Sutton <william AT trilug DOT org>
To: Wynfield Henman <wynfield AT gmail DOT com>
Cc: cygwin AT cygwin DOT com
Subject: Re: is perl braindead?
In-Reply-To: <195b3f1f0706230058s1a70cfc0iac2f45e06508c587@mail.gmail.com>
Message-ID: <Pine.LNX.4.58.0706230447490.17018@dargo.trilug.org>
References: <195b3f1f0706230058s1a70cfc0iac2f45e06508c587 AT mail DOT gmail DOT com>
MIME-Version: 1.0
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

No...depends on where you run that script from.  If you run it anywhere 
outside of /bozo, it doesn't have the full path, so -d fails.  If you 
change your test to

    if ( -d "$ldir/$_" ) { print "This is directory: $_\n"; next; }

then it works.

-- 
William Sutton

On Sat, 23 Jun 2007, Wynfield Henman wrote:

> From what I read the following should work, but it doesn't.
> Can  one of you familiar with cygwin's perl help me out.
> 
> Why doesn't the test, -d, for directory work on the subdirectory?
> It should, in my considered opinion.
> Below is sufficient code to perform a simple test.
> 
> Your help is appreciated.
> 
> Regards,
>   wynfield
> 
> prepare for the test from the command line:
> $ mkdir /bozo
> $ mkdir  /bozo/bozo_the_clown_dir
> 
> Check this:
> find /bozo -type d -print
> /bozo
> /bozo/bozo_the_clown_dir
> -- ok we have a directory and it has a subdirectory
> 
> Sample code:
> ------------------ start of simple perl program
> #! /bin/perl
> 
> my $ldir="/bozo";
> 
>     if ( ! opendir DH, $ldir)
> 	{
> 	print "Couldn't open as a dir: $ldir. \n";
> 	exit 0;
> 	}
> 
>     print "Processing directory: $ldir\n";
>     while ( $_ = readdir(DH) ) 	   # will be either a file or directory name
>         {
>         if ( $_ eq "." or $_ eq ".." ) { print "dir . or ..\n"; next; }
>         if ( -d $_ ) { print "This is directory: $_\n"; next; }
>         print "Escaped detection $_\n";
> 	}
> 
>     close (DH);
> ---------------------------- end of sample code
> 
> --
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> Problem reports:       http://cygwin.com/problems.html
> Documentation:         http://cygwin.com/docs.html
> FAQ:                   http://cygwin.com/faq/
> 
> 
> 

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019