Leo Charre > File-Filename > File::Filename



Annotate this POD

View/Report Bugs
Module Version: 1.05   Source  


File::Filename - expect a filename to be named by a person to be metadata


A lot of people use the filename as a place to insert metadata for the file. This module has some routines to help with treating those filenames. This code takes into consideration what human beings would name files as.

People often expect a space to be *part of* something. To us, used to the prompt, a space is a delimiter, not a delimeter.

People see an underscore and it is a delimiter to them, but to us it is a "word character". This is one of a colleciton of modules to help consolidate the real world of file archiving in offices (multiple human users naming files by hand) with the needs of people maintaining such filesystem hierarchy structures.


        use File::Filename 'get_filename_segments';
        map { 
                my $segments = get_filename_segments($_); 
                ### $segments
        } grep { !/^\.+$/ } readdir DIR;
        closedir DIR;

get_filename_segments() ^

argument is a filename, can be absolute path (the location is ignored) optional argument is a quoted regex that matches non field characters (delimiters). returns array ref

Default regex is qr/[^a-zA-Z0-9 ]+/

In the below examples, You see the filename, and the resulting elements

        122706-BRANDYWINE WISCONSIN LLC-005779-@API.pdf  
   ['122706','BRANDYWINE WISCONSIN LLC','005779','API','pdf']
        122706-GUARDIAN REALTY MANAGEMENT INC-005776-@API.pdf 
   [122706','GUARDIAN REALTY MANAGEMENT INC','005776','API','pdf]
        122705-V & F COFFEE INC-004702-@API.pdf 
   [122705','V','F COFFEE INC','004702','API','pdf]

What if you wanted the ampersand to be part of word characters?

   $File::Filename::delimiter = qr/[^\&a-zA-Z0-9 ]/;

   # or
   get_filename_segments($filename, qr/[^\&a-zA-Z0-9 ]/); 

Empty segments are not returned.




Leo Charre leocharre at cpan dot org


Copyright (c) 2009 Leo Charre. All rights reserved.


This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e., under the terms of the "Artistic License" or the "GNU General Public License".


This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the "GNU General Public License" for more details.

syntax highlighting: