Just another Perl shrine | |
PerlMonks |
Re^8: Working with Binary Numbersby CountZero (Bishop) |
on Sep 25, 2007 at 20:48 UTC ( [id://641038]=note: print w/replies, xml ) | Need Help?? |
Beginning with perl 5.6.0 glob uses File::Glob which despite its name is not limited to be used on files. Actually the argument to glob uses a little language of its own which describes the pattern to search for with meta-characters: (from the docs)
blokhead (ab)uses this pattern-description language by replacing each '-' with {1, 0} to give that placeholder a possible value of 1 OR 0. glob("1{1,0}1") will happily expand to 111 and 101, since unless you include a wildcard character (* or ?) or a character class in your pattern it will NOT go to the filesystem to give you back the list of files but rather expands immediately to all possible values which are allowed by the pattern. It seems to be a (useful) side-effect of the pre-filesystem lookup pre-processing of the pattern to expand {pat,pat,...} strings. Updated: as per tye's comments CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
In Section
Seekers of Perl Wisdom
|
|