I have a directory will create every day file like '2018-08-14-9-22-4', the file name created is by yyyy-mm-dd-h-m-s, how to check file is exists by substring like '2018-08-14' ? and get the file full name and file size ?
my $file = "$yy-$mm-$dd-$hh-$mm-$ss";
my $path = '/home/httpd/doc/$user/$year/[every day file]'
Your path should be double-quoted, if it contains variables. If the path is single-quoted,
$file
and$year
won't get interpolatedSimplest way would be to use the pattern matching in
glob
, and then usestat
on the file.or better yet... use
File::stat
I answered a similar question on r/perl that's worth reading if you interested in the different ways to do what you want
UPDATE
If you have created a filename variable, and you want to check if it exists, just use the file test operators