Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Inconsistent results from (dos)glob

Reply
Thread Tools

Inconsistent results from (dos)glob

 
 
Theo van den Heuvel
Guest
Posts: n/a
 
      01-27-2010
Hi,

The following script behaves differently on two Windows machines, one
XP with v5.10.0, the other Vista with v5.10.1. Here is the script:

<script>

#!/usr/bin/perl
use strict;
use warnings;

use FindBin qw($Bin);
# use File:osGlob 'glob';

my $subdir = "$Bin/FIResources";
my @file = <"$subdir/*">;
my @file_again = glob("\"$subdir\"/*");
print "angular: ", join(', ', @file), "\n";
print "glob: ", join(', ', @file_again), "\n";

</script>

On XP the script lists the files in both print statements. On that
system the path
contains spaces (I know, not my idea).
The Vista directory does not contain spaces, but both arrays remain
empty.

Any suggestions?

Thanks

Theo van den Heuvel
 
Reply With Quote
 
 
 
 
Theo van den Heuvel
Guest
Posts: n/a
 
      01-28-2010
On 28 jan, 00:53, Ben Morrow <(E-Mail Removed)> wrote:
> Quoth Theo van den Heuvel <(E-Mail Removed)>:
>


>
> > The following script behaves differently on two Windows machines, one
> > XP with v5.10.0, the other Vista with v5.10.1. Here is the script:

>
> > <script>



>
> > Any suggestions?

>
> Have you verified that FindBin is working properly (it doesn't always)
> and that the FIResources directory actually exists?
>
> Do you have read permission (or whatever permission is required on Win32
> to call readdir) on the directory? What do you get if you call
> opendir/readdir directly?
>
> Ben


Hi Ben,

FindBin was working properly and there is no difference in permissions
that I am aware of.

I added:

opendir(my $dir, $subdir) or die "can't opendir $subdir: $!";
my @file_yetagain = readdir($dir);
print "readdir: ", join(', ', @file_yetagain), "\n";
closedir $dir;

and that works okay on both platforms. That proves that the files are
really there.

I am still stumped on how the script can fail on the second machine.

Thanks,

Theo
 
Reply With Quote
 
 
 
 
Theo van den Heuvel
Guest
Posts: n/a
 
      01-28-2010
On 28 jan, 02:25, Ben Morrow <(E-Mail Removed)> wrote:
> Quoth Theo van den Heuvel <(E-Mail Removed)>:
>


>
> Then I'm afraid you need to go grubbing around in File:osGlob adding
> debug statements until you find where the problem is (or use the
> debugger, if that's your cup of tea).
>
> Ben


Something like that. However it is both DosGlob and the ordinary glob
that misbehaves.
I need to get some sleep first, and will apply the debugger first
thing in the morning.

Theo
 
Reply With Quote
 
Ilya Zakharevich
Guest
Posts: n/a
 
      01-28-2010
On 2010-01-27, Theo van den Heuvel <(E-Mail Removed)> wrote:
> my $subdir = "$Bin/FIResources";
> my @file = <"$subdir/*">;
> my @file_again = glob("\"$subdir\"/*");


If this works, then ONLY due to bugs in glob() (this is IMO; prove me wrong if
you can). Use
bsdglob( "$subdir/*" )
instead.

Hope this helps,
Ilya
 
Reply With Quote
 
Theo van den Heuvel
Guest
Posts: n/a
 
      01-28-2010
On 28 jan, 04:42, Ilya Zakharevich <(E-Mail Removed)> wrote:
> On 2010-01-27, Theo van den Heuvel <(E-Mail Removed)> wrote:
>
> > my $subdir = "$Bin/FIResources";
> > my @file = <"$subdir/*">;
> > my @file_again = glob("\"$subdir\"/*");

>
> If this works, then ONLY due to bugs in glob() (this is IMO; prove me wrong if
> you can). *Use
> * bsdglob( "$subdir/*" )
> instead.
>
> Hope this helps,
> Ilya


Dear Ilya,

bsd_glob() does work consistently on both systems. This means I have a
solution and that makes me a happy man.

My confusion, however, has increased, because the documentation
suggests that glob is implemented in terms of bsd_glob. I added the
double quotes to avoid that glob splits
the path on the spaces. (Spaces in names IMO is one of the most
unfortunate design mistakes in Windows).

Anyway, thanks a million, Ilya,

Theo
 
Reply With Quote
 
Ilya Zakharevich
Guest
Posts: n/a
 
      01-28-2010
On 2010-01-28, Theo van den Heuvel <(E-Mail Removed)> wrote:
>> > my @file_again = glob("\"$subdir\"/*");

>>
>> If this works, then ONLY due to bugs in glob() (this is IMO; prove me wrong if
>> you can). *Use
>> * bsdglob( "$subdir/*" )
>> instead.


> bsd_glob() does work consistently on both systems. This means I have a
> solution and that makes me a happy man.
>
> My confusion, however, has increased, because the documentation
> suggests that glob is implemented in terms of bsd_glob.


.... but interprets spaces differently...

> I added the double quotes to avoid that glob splits the path on the
> spaces.


And what made you think that this would "avoid this"? (Except, maybe,
experiments with a buggy implementation?)

Yours,
Ilya
 
Reply With Quote
 
Theo van den Heuvel
Guest
Posts: n/a
 
      01-28-2010
On 28 jan, 12:39, Ilya Zakharevich <(E-Mail Removed)> wrote:
> On 2010-01-28, Theo van den Heuvel <(E-Mail Removed)> wrote:
>
> >> > my @file_again = glob("\"$subdir\"/*");

>


> > My confusion, however, has increased, because the documentation
> > suggests that glob is implemented in terms of bsd_glob.

>
> ... but interprets spaces differently...


Ok. Something I am missing in the documentation.

>
> > I added the double quotes to avoid that glob splits the path on the
> > spaces.

>
> And what made you think that this would "avoid this"? *(Except, maybe,
> experiments with a buggy implementation?)


Yes. Naively, surely, I guessed from the fact that you can use double
quotes in a Windows command box in the same way. Prior to your
comments I had no indication that glob was buggy. I am still in shock
about that.

>
> Yours,
> Ilya


Thanks,

Theo
 
Reply With Quote
 
Martijn Lievaart
Guest
Posts: n/a
 
      01-28-2010
On Thu, 28 Jan 2010 00:34:37 -0800, Theo van den Heuvel wrote:

> (Spaces in names IMO is one of the most unfortunate design mistakes in
> Windows).


Spaces are fine. Newlines in filenames on Unix, now there is trouble!

M4
 
Reply With Quote
 
sreservoir
Guest
Posts: n/a
 
      01-29-2010
On 1/28/2010 2:40 PM, Martijn Lievaart wrote:
> On Thu, 28 Jan 2010 00:34:37 -0800, Theo van den Heuvel wrote:
>
>> (Spaces in names IMO is one of the most unfortunate design mistakes in
>> Windows).

>
> Spaces are fine. Newlines in filenames on Unix, now there is trouble!


not really. you can have newlines without trouble. however, if you use
one of those filesystems that let you have nulls in filenames, some of
the standard utilities might segfault or overflow.

funny how segfault is in my dictionary and not filename.

--

"Six by nine. Forty two."
"That's it. That's all there is."
"I always thought something was fundamentally wrong with the universe"
 
Reply With Quote
 
John Bokma
Guest
Posts: n/a
 
      01-29-2010
Theo van den Heuvel <(E-Mail Removed)> writes:

> the path on the spaces. (Spaces in names IMO is one of the most
> unfortunate design mistakes in Windows).


Heh, I would say it the other way around: not supporting spaces in
filenames/directory names is a design mistake. (One that is even to some
extent visible on the www...)

--
John Bokma j3b

Hacking & Hiking in Mexico - http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inconsistent results from int(floatNumber) gershar Python 5 10-26-2010 01:07 PM
Inconsistent results uploading stereo to YouTube Doc Computer Support 1 04-23-2008 11:20 PM
Inconsistent Program Results Francine.Neary@googlemail.com C Programming 20 03-18-2007 11:39 PM
Help: Inconsistent results of org.w3c.dom-based code evoked from different programs Bryan Java 2 09-23-2004 08:38 AM
Same code, inconsistent results -- Please Help! Neo Geshel ASP .Net 2 11-03-2003 09:41 PM



Advertisments