Ok, so I brought it here:
I first get all the filenames into one text file and then I run the following, on the file:
use strict;
use warnings;
use Date::Parse;
my @AoA_files=();
open IN, $ARGV[0];
while(<IN>)
{
my $infile=$_;
chomp $infile;
if($infile=~/^(\d+)\_(\d+)_(\d+)_(\d+)_(\d+)_(\d+)_(\d+)_(.*)/)
{
my $uid=$1;
my $year=$2;
my $month=$3;
my $day=$4;
my $hour=$5;
my $minute=$6;
my $second=$7;
my $actual_filename=$8;
my $timestamp = "$year-$month-$day"."T"."$hour:$minute:$second
+";
if ( grep { $_->[1] eq $actual_filename } @AoA_files ) #if fil
+ename exists, keep only the most recent one
{
#compare the timestamps
my $existing_timestamp = $_->[0];
my $difference_in_seconds = str2time($timestamp) - str2tim
+e($existing_timestamp);
if($difference_in_seconds > 0) #current date is newer than
+ the one in the AoA - use this one
{
push @AoA_files, [ $timestamp, $actual_filename];
}
}
else #add it normally to the AoA
{
push @AoA_files, [ $timestamp, $actual_filename];
}
}
}
My idea here is to eventually create a second file with the full filenames that I need to keep.
Does that make sense?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|