Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Re: globing files with spaces problem.

by Nabuku (Initiate)
on Aug 10, 2002 at 17:37 UTC ( #189204=note: print w/replies, xml ) Need Help??


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 (Priest) 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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://189204]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2018-05-27 04:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?