> puts stats.sort {|x,y| x[1] <=> y[1]}.max
> 
> This explicitly sorts by the 2nd value in the to_a array, which is the 
> mtime.

Thanks, but that does not work because its sorting on the time only, for 
example sorting on 1052, 1054, 110, 1042.


root  wheel  38608780 Oct 29 10:52 
/usr/local/vrep/prod_db_bkup_Thr2009-10-291052.gz
root  wheel  38608793 Oct 29 10:54 
/usr/local/vrep/prod_db_bkup_Thr2009-10-291054.gz
root  wheel  38608802 Oct 29 11:00 
/usr/local/vrep/prod_db_bkup_Thr2009-10-29110.gz
root  wheel  38609193 Oct 30 10:42 
/usr/local/vrep/prod_db_bkup_Fri2009-10-301042.gz

so I am using this, but I could not get my each loop to work
please help!


stats = Hash.new
    DB_BKUP1.each do |dbfile|
        stats[dbfile] = [File.stat(dbfile).mtime.to_i]
    end

    statsA     = stats.sort { |x,y| x[1] <=> y[1] }.to_a
    oldest     = statsA[0][1].to_s.to_i

    p statsA
    p "1st oldest:, oldest
    (0..statsA.length-1).step(1) do |i|
        if #{statsA[i][1]} < #{oldest}
            oldest = statsA[i][1]
        end
    end
    p "after if clause oldest:", oldest

__OUTPUT__

[["/usr/local/vrep/prod_db_bkup_Thr2009-10-291052.gz", [1256827961]], 
["/usr/local/vrep/prod_db_bkup_Thr2009-10-291054.gz", [1256828056]], 
["/usr/local/vrep/prod_db_bkup_Thr2009-10-29110.gz", [1256828444]], 
["/usr/local/vrep/prod_db_bkup_Fri2009-10-301042.gz", [1256913745]]]

"1st oldest:"
[1256827961]
"after if clause oldest:"
[1256913745]
-- 
Posted via http://www.ruby-forum.com/.