For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > August 2005 > spaces in paths









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author spaces in paths
Eric.Medlin@gmail.com

2005-08-29, 6:59 pm

The following code doesn't print out the file list.

#!/usr/bin/perl

$inFolder = "~/folder space";
@folders = <$inFolder/*>;
print "@folders\n";

Adding double quotes around like @folders = <"$inFolder"/*>; fixes the
problem, but then
$inFolder = "~/folder_nospace"; doesn't print out anything. How do I
get it print out the file list all the time.

Gunnar Hjalmarsson

2005-08-29, 6:59 pm

Eric.Medlin@gmail.com wrote:
> The following code doesn't print out the file list.
>
> #!/usr/bin/perl
>
> $inFolder = "~/folder space";
> @folders = <$inFolder/*>;
> print "@folders\n";
>
> Adding double quotes around like @folders = <"$inFolder"/*>; fixes the
> problem, but then
> $inFolder = "~/folder_nospace"; doesn't print out anything. How do I
> get it print out the file list all the time.


You may want to try:

$inFolder =~ s/ /\\ /g;

Or, probably safer, use opendir() and readdir() instead.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com