Carl Jolley wrote:

> On Thu, 3 Apr 2003, Daniel Gross wrote:
>
> > Hello,
> >
> > I am trying to find all files that have zero size, but it doesn't work
> > -- why?
> >
> >
> > my @tmpArray = glob("$dirName/*.tif");
> > my @zeroFiles = getZeroSizeTiffs(@tmpArray);
> >
> > sub getZeroSizeTiffs {
> >       my (@tiffFiles) = @_;
> >
> >       my @zeroFiles = grep { -z $_ } @tiffFiles;
> >
> >       return @zeroFiles;
> > }
> >
>
> My guess is that the $dirName is giving you problems. Since you glob'ed
> with a directory name, my guess is that the list returned by the glob
> was just filenames, without the directory prepended. Try this for your
> grep and see if it works:
>
> my @zeroFiles = grep { -z "$dirName/$_" } @tiffFiles;
>
> **** [EMAIL PROTECTED] <Carl Jolley>
> **** All opinions are my own and not necessarily those of my employer ****
>

I think Daniel's doing it right.  My guess is his pathnames have spaces in them.
I first noticed this weirdness on Windoze and I thought it was just normal stuff,
but I just verified it on Linux too.

Try this test on for size:
[NB. This script removes the directory: "a directory with spaces" if it exists ;-]
==================================================================================
#!/usr/bin/perl -w

use strict;
use File::Path 'rmtree';
use FileHandle;
use File::Glob qw();

my $tstdir = 'a directory with spaces';
-d $tstdir and File::Path::rmtree( $tstdir );
mkdir( $tstdir ) or die( "mkdir: $tstdir: $!" );

foreach ( qw( a b c d e f ) )
{
    new FileHandle( ">$tstdir/$_.tif" ) or
        die( "create: '$tstdir/$_.tif': $!" );
}

foreach ( glob( qq($tstdir/*.tif) ) )
{
    print "glob: got: $_\n";
}
print "Glob(", $File::Glob::GLOB_ERROR, "): $!\n" if ( $File::Glob::GLOB_ERROR );

foreach ( CORE::glob( qq($tstdir/*.tif) ) )
{
    print "CORE::glob: got: $_\n";
}
print "Glob(", $File::Glob::GLOB_ERROR, "): $!\n" if ( $File::Glob::GLOB_ERROR );

foreach ( File::Glob::glob( qq($tstdir/*.tif) ) )
{
    print "File::Glob:glob: got: $_\n";
}
print "Glob(", $File::Glob::GLOB_ERROR, "): $!\n" if ( $File::Glob::GLOB_ERROR );
==================================================================================
I get the same output on WindowsNT(ASPerl5.6.0-623) and RHLinux7.1(Perl5.6.0):
glob: got: a
glob: got: directory
glob: got: with
CORE::glob: got: a
CORE::glob: got: directory
CORE::glob: got: with
File::Glob:glob: got: a directory with spaces/a.tif
File::Glob:glob: got: a directory with spaces/b.tif
File::Glob:glob: got: a directory with spaces/c.tif
File::Glob:glob: got: a directory with spaces/d.tif
File::Glob:glob: got: a directory with spaces/e.tif
File::Glob:glob: got: a directory with spaces/f.tif
==================================================================================
FWIW, perl crashes on both Linux and Windoze if I call CORE::glob when I do:
    use File::Glob qw(:glob);
in the above program.  On Linux I get a SEGV, and on Windoze the disk just spins...

rgr


_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to