@ARGV and droplets, sorry
[email protected] (Axel Rose) Tue, 4 Dec 2001 00:27:28 +0100
| Newsgroups | perl.macperl.porters |
|---|---|
| Message-ID | <p05100302b831b9c6728b@[172.16.22.38]> |
Oh dear, I was faster writing than thinking...
$ARGV[0] is ok in the bug report "@ARGV and droplets".
It looks like glob() does the unwanted splitting.
Here's a workaround I'm using in the moment which saves
me from using File::Find and avoids glob().
#!perl -w
use strict;
package WalkTree;
use strict;
my $MACOS = ( $^O =~ /macos/i ) || 0;
my $WINOS = ( $^O =~ /win/i ) || 0;
my $DIRSEP = "/";
$MACOS and $DIRSEP = ":";
$WINOS and $DIRSEP = "\\";
sub walktree {
my ( $dir, $filefunc, $dirfunc ) = @_;
$MACOS and $dir =~ s/:$//;
if ( -d $dir ) {
my @values;
local *DH;
opendir DH, $dir or warn "opendir '$dir' failed\n$!";
my $file;
while ( defined( $file = readdir DH )) {
!$MACOS and next if( $file eq '.' or $file eq '..' );
$MACOS and next if( $file eq "Icon\n" );
push @values, walktree( "$dir$DIRSEP$file", $filefunc, $dirfunc );
}
closedir DH;
ref $dirfunc ? return $dirfunc->($dir, @values) : return @values;
} else {
ref $filefunc ? return $filefunc->($dir) : return;
}
}
package main;
die "no input, no output\n" unless @ARGV;
print "DEBUG: \$ARGV[0] = $ARGV[0]\n";
my @files;
if( -d $ARGV[0] ) { @files = WalkTree::walktree( $ARGV[0], sub { @_ }, undef ) }
else { @files = @ARGV }
my $i = 0;
for ( @files ) { print $i++, " '$_'\n" }
__END__
hope this is accepted as excuse for a confusing error report.
Axel