[Israel.pm] glob function give wrong results

Offer Kaye offer.kaye at gmail.com
Sat Mar 19 12:54:47 PST 2005


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