http://www.perlmonks.org?node_id=70597


in reply to Can I open a specific file (eg. '.log') without knowing the actual name of it?

glob.
use strict; use IO::File; my @logFiles = glob( '*.log' ); my @data; for ( @logFiles ) { # You can further limit your file names thusly: die "Weird File Name" if m/[^a-zA-Z0-9._-]/; my $fh = IO::File->new( '< $_' ) or die "Open Failed for '$_', $!"; push @data, <$fh>; # Do something with the file $fh->close(); }
  • Comment on Re: Can I open a specific file (eg. '.log') without knowing the actual name of it?
  • Download Code