in reply to Re: globing files with spaces problem.
in thread globing files with spaces problem.

Hi

When I've used bsd_glob, I got an endless loop. I'm probably doing something wrong...

Here's the code I've used:

#!/usr/bin/perl -w use File::Glob qw(bsd_glob); my $source_dir = "/home/haim/tmp/lists"; sub init_source_list { chdir $source_dir or die "Cannot change dir to $source_dir! ($!)"; while (defined($sourcefile = bsd_glob("*"))) { # for every file in +this # directory if (-d $sourcefile) { # if the file is actually a directory... while (defined($ver = bsd_glob("$sourcefile/*"))) { #$ver =~ s/.*\///; #remove everything before the "/". $apps{$sourcefile}{$ver} = undef; # add an empty key to # %apps{$sourcefile} } } else { $apps{$sourcefile} = undef; # add an empty key in the hash # %apps } } } &init_source_list; foreach $key (keys %apps) { if (keys %{ $apps{$key} }) { foreach $vkey (keys %{ $apps{$key} }) { print "$source_dir/$key/$vkey\n"; } } else { print "$source_dir/$key\n"; } }

Thanx
--
Nabuku

Replies are listed 'Best First'.
Re: Re: Re: globing files with spaces problem.
by kschwab (Vicar) on Aug 10, 2002 at 17:42 UTC
    Change:

    while (defined($sourcefile = bsd_glob("*")))

    to:

    foreach my $sourcefile (bsd_glob("*"))

    bsd_glob doesn't act like the <*.foo> operator, as CORE::glob does.

      Thanx, this one solved it!!

      --
      Nabuku