[Israel.pm] Re: glob function give wrong results

Rami Addady rami at active.co.il
Sun Mar 20 02:33:09 PST 2005


Thank it work.

Rami

> From: Offer Kaye
> Subject: Re: [Israel.pm] glob function give wrong results
> To: Perl in Israel <perl at perl.org.il>
> Message-ID: <56942505031912542539c2ff at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On Sat, 19 Mar 2005 19:10:01 +0200, Rami Addady <rami at active.co.il> wrote:
>> Hi,
>>
>> I have some problem using glob function, maybe I'm missing some thing.
>> glob give wrong result when file name contain space.
>>
>> For example:
>>
>> I have 4 file:
>> >ls -1 work*
>>
>> w1 Open WebMail.url.abc
>> w1-Open-WebMail.url.abc
>> w1 Open WebMail.url.abc__18-22__19-03-2005
>> w1-Open-WebMail.url.abc__18-22__19-03-2005
>>
>> When running this program:
>>
>> >cat glob_problem.pl
>>
>> $fname = "w1-Open-WebMail.url.abc";
>> print "file name: $fname\n";
>> my @files = glob($fname."*__??-??-????");
>> print "After glob: @files \n";
>> $fname = "w1 Open WebMail.url.abc";
>> print "file name: $fname\n";
>> my @files = glob($fname."*__??-??-????");
>> print "After glob: @files \n";
>>
>> >perl glob_problem.pl
>>
>> file name: w1-Open-WebMail.url.abc
>> After glob: w1-Open-WebMail.url.abc__18-22__19-03-2005
>> file name: w1 Open WebMail.url.abc
>> After glob: w1 Open
>>
>> Any Idea?
>>
>> Regards,
>> Rami Addady
>>
>
> The problem is the spaces in the name you're passing - the core glob
> function thinks you're passing it multiple patterns. Try escaping the
> space in the name, e.g.:
> $fname = "w1\ Open\ WebMail.url.abc";
>
> If you're on a Win based system, you can try using File::DosGlob -
> http://perldoc.perldrunks.org/File/DosGlob.html
>
> For more info, see the File::Glob documentation:
> http://perldoc.perldrunks.org/File/Glob.html
>
> Regards,
> -- 
> Offer Kaye
> 




More information about the Perl mailing list