Treex::Core::Files - helper class for iterating over filenames
version 2.20150928
package My::Class; use Moose; has from => ( is => 'ro', isa => 'Treex::Core::Files', coerce => 1, handles => [qw(next_filename current_filename)], ); # and then my $c = My::Class(from=>'f1.txt f2.txt.gz @my.filelist'); while (defined (my $filename = $c->next_filename)){ ... } #or while (my $filehandle = $c->next_filehandle){ ... } # You can use also wildcard expansion my $c = My::Class(from=>'!dir??/file*.txt');
The @filelist and !wildcard conventions are used in several tools, e.g. 7z or javac. For a large number of files, list the file names in a file - one per line. Then use the list file name preceded by an @ character.
Methods <next_*> serve as iterators and return undef if the called after the last file is reached.
Returns the total number of files contained by this instance.
Returns ordinal number (1..number_of_files) of the current file.
Returns the current filename or undef if the iterator is before the first file (i.e. next_filename has not been called so far) or after the last file.
next_filename
Returns the next filename (and increments the file_number).
Opens the current file for reading and returns the filehandle. Filename "-" is interpreted as STDIN. Filenames with extension ".gz" are opened via PerlIO::via::gzip (ie. unzipped on the fly).
Returns the next filehandle (and increments the file_number).
Returns the content of the next file (slurp) and increments the file_number.
Returns the next line of the current file. If the end of file is reached and attribute join_files_for_next_line is set to true (which is by default), the first line of next file is returned (and file_number incremented).
join_files_for_next_line
Returns MD5 hash computed from the filenames and last modify times.
Helper method that expands comma-or-space-separated list of filenames and returns an array reference containing the filenames. If the string starts with "!", it is interpreted as wildcards (see Perl glob). If a filename starts with "@" it is interpreted as a file list with one filename per line.
Martin Popel <popel@ufal.mff.cuni.cz>
Copyright © 2011 by Institute of Formal and Applied Linguistics, Charles University in Prague
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Treex::Core, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Treex::Core
CPAN shell
perl -MCPAN -e shell install Treex::Core
For more information on module installation, please visit the detailed CPAN module installation guide.