perlrush2011 has asked for the wisdom of the Perl Monks concerning the following question:

Greetings,
I have a set of files in a directory with their epoch date/time. I want to know what is the best way to get all the files under the same day for example:

file1_1344261690 = 6 Aug 2012 15:1:30
file2_1344264601 = 6 Aug 2012 15:50:1
file3_1344318351 = 7 Aug 2012 6:45:51
file4_1344321755 = 7 Aug 2012 7:42:35

I want to gather all files with the same date and put the contents of the files into file large file for example:

file_6aug.txt would contain the contents of file1_1344261690 & file2_1344264601
file_7aug.txt would contain the contents of file3_1344318351 & file4_1344321755

What is the best way to get this done?
Cheers,

Replies are listed 'Best First'.
Re: Epoch get all files with same day
by jethro (Monsignor) on Aug 15, 2012 at 11:31 UTC

    Where do you have problems? With the localtime() function you can get the day and month out of the epoch time. Or use one of the many date modules like DateTime. For the copying of the files you might use the shell with system("cat $sourcefile >> file_${date}.txt");

Re: Epoch get all files with same day
by aitap (Curate) on Aug 15, 2012 at 11:55 UTC
    Use glob or opendir to get the file names. Use regexp match (see perlretut) to match the UNIX timestamp. Use localtime and array splicing to determine the date. Use open, readline (also <$filehandle>), print, close to manipulate file contents.
    Sorry if my advice was wrong.
Re: Epoch get all files with same day
by Anonymous Monk on Aug 15, 2012 at 11:13 UTC

    What is the best way to get this done?

    First do it any way you can

      Here you go

      #!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw' dd '; my %Turtles = ...; # Find "%seen" in perlfaq4/How can I get the unique keys from two hash +es? my %buckets; while( my( $name, $epoch ) = each %Turtles ) { my $ymd = POSIX::strftime('%Y-%m-%d', gmtime( $epoch ) ); push @{ $buckets{ $ymd } }, $name; } dd \%buckets; __END__ { "2012-08-09" => ["B1", "B2"], "2012-08-11" => ["C1", "C2"], "2012-08-13" => ["D1", "D2"], "2012-08-15" => ["A1", "A2"], }