[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Problems with the "-x" file tests



Bill Hutten wrote:
> 
> I'm having a problem that's almost certainly attributable to my
> stupidity, and i'd appreciate the lists' help:
> 
> ...given the following:
> 
> foreach $item (@list) {
>         if (-d $item) {
>                 print "directory: $item\n";
>         }else{
>                 print "$item\n";
>         }
> }
> 

One needs to test a fully qualified (absolute) pathname to ensure
success, as perl has no context to prove or disprove the type of file
 it is given:-

therefore the followingmod would work would work:-

$basedir = "Hard drive:Program Folder";
opendir(DIR, $basedir) or die;
@list = readdir(DIR);
foreach $item ($basedir) {
    $abs_path = $basedir.":".$item;
    if (-d $abs_path)
...

Maybe perlfunc.pod could do with a modification to cut the confusion?
I'll look into it.


Enjoy

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch