regex - bsd_glob behaving differently on different machines -
i using bsd_glob
list of files matching regular expression file path. perl utility working on rhel
, not on suse 11/aix/solarix
, exact same set of files , same regular expression. googled limitations of bsd_glob
, couldn't find information. can point what's wrong?
below regular expression file path searching for:
/datafiles/data_one/level_one/*/data*
i need files beginning data, in directory present under 'level_one'.
works on rhel
box, not on other unix
, suse linux
.
below code snipped using bsd_glob
foreach $file (bsd_glob ( "$filename", glob_err )) { if ($filename =~ /[[:alnum:]]\*\/\*$/) { next if -d $file; $filelist{$file} = $permissions; $total++; } elsif ($filename =~ /[[:alnum:]]\*$/) { $filelist{$file} = $permissions; $total++; } else { $filelist{$file} = $permissions; $total++; } }
in case facing issue, /datafiles/data_one/level_one/*/data*
being passed bsd_glob
. creating map ($filelist
) of files returned bsd_glob
based on regular expression passing it. $permissions
predefined value.
any appreciated.
the problem here looks you're confusing glob patterns , regular expressions.
/[[:alnum:]]\*\/\*$/ /[[:alnum:]]\*$/
you're looking file called *
that, under directory containing literal *
.
whilst technically possible it's strange. , cannot ever match patterns glob
should find.
do perhaps mean:
m,\w+.*/.*$,
(different delimiter clarity)
also - why using bsd_glob
specifically? file::glob
:
since v5.6.0, perl's core::glob() implemented in terms of bsd_glob(). note don't share same prototype--core::glob() accepts single argument. due historical reasons, core::glob() split argument on whitespace, treating multiple patterns, whereas bsd_glob() considers them 1 pattern. see :bsd_glob under exports, below.
comment:
i used bsd_glob instead of glob there slight difference in way works on different unix platforms. specifically, above mentioned pattern, on unix platforms, didn't return file having exact name 'data', , returned files appended data.
i'm little surprised @ that, should implementing same mechanisms , same posix standard on globbing. there chance there's permissions related problem instead?
but otherwise perhaps try not using glob
heavy lifting, , instead compare file name bunch of regular expressions. (although note - res have different syntax)
foreach $file ( glob('/datafiles/data_one/level_one/*/*') ) { next unless $filename =~ m,data\w+$,; }
Comments
Post a Comment