A
annesville
Hello All,
I am still learning Perl. I am trying to write a script to
recursively list all the directories starting from a specified path.
Unfortunately it seems that the globbing function handles paths with/
without spaces in them very differently as shown by the test case
script below.
Some research seems seems to indicate that I would be better off using
opendir/readdir. Accepted, but I would like, as part of my learning
experience, for someone to explain in simple terms WHY the below
script handles different paths differently. Please note that I have
used literal paths, but in application I would obviously need to use a
variable - so if you suggest escaping the space, it is not so simple
(although it is do-able), and doesn't make any difference anyway.
I am using ActivePerl 5.8.8.820
Regards,
Nicolas
----- START PERL -----
use strict;
use warnings;
my $file;
print "--- Windows, unquoted ---\n"; # Returns a list of all files and
directories in 'C:\Windows'
foreach $file (<c:/windows/*>) {print "$file\n";};
print "--- Windows, quoted ---\n"; # Returns nothing
foreach $file (<"c:/windows/*">) {print "$file\n";};
print "--- Program Files, unquoted ---\n"; # Returns 'c:/program' as
the only result
foreach $file (<c:/program files/*>) {print "$file\n";};
print "--- Program Files, quoted ---\n"; # Returns a list of all the
files and directories in 'C:\Program Files'
foreach $file (<"c:/program files/*">) {print "$file\n";};
----- END PERL -----
I am still learning Perl. I am trying to write a script to
recursively list all the directories starting from a specified path.
Unfortunately it seems that the globbing function handles paths with/
without spaces in them very differently as shown by the test case
script below.
Some research seems seems to indicate that I would be better off using
opendir/readdir. Accepted, but I would like, as part of my learning
experience, for someone to explain in simple terms WHY the below
script handles different paths differently. Please note that I have
used literal paths, but in application I would obviously need to use a
variable - so if you suggest escaping the space, it is not so simple
(although it is do-able), and doesn't make any difference anyway.
I am using ActivePerl 5.8.8.820
Regards,
Nicolas
----- START PERL -----
use strict;
use warnings;
my $file;
print "--- Windows, unquoted ---\n"; # Returns a list of all files and
directories in 'C:\Windows'
foreach $file (<c:/windows/*>) {print "$file\n";};
print "--- Windows, quoted ---\n"; # Returns nothing
foreach $file (<"c:/windows/*">) {print "$file\n";};
print "--- Program Files, unquoted ---\n"; # Returns 'c:/program' as
the only result
foreach $file (<c:/program files/*>) {print "$file\n";};
print "--- Program Files, quoted ---\n"; # Returns a list of all the
files and directories in 'C:\Program Files'
foreach $file (<"c:/program files/*">) {print "$file\n";};
----- END PERL -----