Perl: can't get time stamps from files in directory --> Use of uninitialized value in line 18 -


My goal: List the * gz files in a directory with the name and creation date.

I wrote the following

  #! Use / usr / bin / perl strict; Use warnings; File :: Use State; Use time: local time; My $ directory = '/home/hans/.config/cqrlog/database'; Opendir (DIR, $ directory) or $ !! My @ files = (reader (dir)); Closedir (DIR); Use a regular expression to find files ending with Foreach $ _ (@files) {# .gz if ($ _ = ~ m / \ .gz $ /) {my $ file_name = $ _; My $ file_time = (state ($ _)) [9]; Print "$ file_time \ n"; }}  

But I keep getting the error seen frequently "use uninitialized value $ file_time in concatenation (.) Or //perl-matching-files.pl string on line 18. " Which is the print line.

I also tried the following: use a regular expression to search for files ending with

  foreach $ _ (@files) {# .gz} Please ($ _ = ~ M / \ .gz $ /) {my $ file_name = $ _; My @file_time_array = (State ($ _); My $ file_time = $ file_time_array [9]; Print $ file_name, "-", $ file_time, "\ n"; }}  

But again this is the bar on the last print line. I also tried a little bit longer, but according to the same result. File names are printed, however, so I have to do something right. I think the time stamp is not read while reading through the array, but I am not very expert to know what is going wrong. It seems that always come on the print line, no insights is appreciated. Cheers.

Instead

  my $ file_time = (stat ($ _ )) [9];  

Try

  My $ file_time = (stat ("$ directory / $ _")) [9];  

Otherwise, you are searching for the /home/hans/.config/cqrlog/database files in the existing code which can only work already specified Directory.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -