Globbing on Win32

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 -----
 
A

annesville

Thanks for the pointers Michelle.

Not that I'm bothered or offended, but... Michele (italian masculine
name as opposed to Michelle, which is a french feminine one).

Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

Whoa! Sorry 'bout that. I obviously don't qualify as a citizen of the
global community yet!

BTW, I am sure there must be a shorter way to write your signiture :)

Nicolas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top