How do I glob with escaped spaces in a directory
When I use: my @foo = glob "/foo/bar baz/*"; or my @foo = glob "/foo/bar\ baz/*"; Glob doesn't return the files in those directories, @foo equals ("/foo/bar"); However, if I do: my @foo = glob "/foo/bar*baz/*"; @foo equals an array with all the files in "/foo/bar\ baz/", which is what I"m trying for. How do I escape spaces? Perldoc glob doesn't say. Thanks in advance, Dan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How do I glob with escaped spaces in a directory
On Thursday, Nov 6, 2003, at 10:21 US/Pacific, Dan Anderson wrote: [..] How do I escape spaces? Perldoc glob doesn't say. [..] an interesting problem, one thing that may influence the problem is how your underlying shell does the 'expansion' - as the perldoc -f glob notes, with perl 5.6 this is resolved with the File::Glob module. How do you normally escape the spaces when you are at the shell level??? the '*' solution is basically cool enough - and yes that with the "bar\ baz" should have worked as you would have expected it. EXCEPT that it was inside double quotes, hence would be interpreted once by perl, which will remove your "\" - so you either want to go with a. print_glob("$dir/foo/bar*baz/*"); b. print_glob( $dir . '/foo/bar\ baz/*'); c. print_glob("$dir/foo/bar\\ baz/*"); and resolve who gets to solve which interpolation where. ciao drieux --- a bit of code to illustrate the fun of it all: my $dir = ; print_glob("$dir/foo/bar baz/*"); print_glob($dir . '/foo/bar baz/*'); print_glob("$dir/foo/bar\ baz/*"); print_glob("$dir/foo/bar*baz/*"); print_glob("$dir/foo/*bar*/*"); print_glob("$dir/foo/bar' 'baz/*"); print_glob( $dir . '/foo/bar\ baz/*'); print_glob("$dir/foo/bar\\ baz/*"); # # sub print_glob { my ($tag) = @_; my @foo = glob $tag; print "given :$tag: we see the glob as:\n"; foreach my $file (@foo) { print "\t:$file:\n"; } } # end of print_glob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How do I glob with escaped spaces in a directory
Dan Anderson wrote: > When I use: > > my @foo = glob "/foo/bar baz/*"; > or > my @foo = glob "/foo/bar\ baz/*"; > > Glob doesn't return the files in those directories, @foo equals > ("/foo/bar"); > > However, if I do: > > my @foo = glob "/foo/bar*baz/*"; > > @foo equals an array with all the files in "/foo/bar\ baz/", which is > what I"m trying for. > > How do I escape spaces? Perldoc glob doesn't say. here is one way doing it: [panda]# touch "foo .txt" [panda]# perl -MFile::Glob=:glob -le 'print bsd_glob("foo .txt",GLOB_QUOTE)' foo .txt [panda]# rm -f "foo .txt" [panda]# perl -MFile::Glob=:glob -le 'print bsd_glob("foo .txt",GLOB_QUOTE)' [panda]# perldoc File::Glob david -- $_=q,015001450154015401570040016701570162015401440041,,*,=*|=*_,split+local$"; map{~$_&1&&{$,<<=1,[EMAIL PROTECTED]||3])=>~}}0..s~.~~g-1;*_=*#, goto=>print+eval -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]