[Perl] time/date differences
Shlomi Fish
shlomif at vipe.stud.technion.ac.il
Thu Oct 31 04:11:13 PST 2002
Hi!
Is there any reason why you don't use plain ls and use the stat() function
to retrieve the information. It would simplify the script greatly.
Regards,
Shlomi Fish
On Thu, 31 Oct 2002, Shlomo Yona wrote:
> Hello.
>
> I am writing code for an "automatic homework grader" for an introduction course
> in c. Following is a description of something I had to do, and I wonder if you
> guys have ideas for better code than I do.
>
> Thanks:
>
>
> I'm writing a script to parse lines like this:
>
> -rw-r--r-- 1 shlomo shlomo 760 Oct 29 23:36 1/022308399/1/hw1.c
> -rw-r--r-- 1 shlomo shlomo 198 Oct 30 17:29 1/066589623/1/targil1.c
> -rw-r--r-- 1 shlomo shlomo 884 Oct 28 13:57 1/306370966/1/home.c
> -rw-r--r-- 1 shlomo shlomo 24583 Oct 28 22:02 1/035846088/1/hw1.c
> -rw-r--r-- 1 shlomo shlomo 218 Oct 28 21:55 1/035846088/1/noam.c
> -rw-r--r-- 1 shlomo shlomo 385 Oct 30 18:09 1/035848688/1/Homework1.c
> -rw-r--r-- 1 shlomo shlomo 266 Oct 30 20:40 1/041955584/1/hw1.c
> -rw-r--r-- 1 shlomo shlomo 584 Oct 28 14:47 1/036000479/1/dudi.c
>
> I want to extract only 3 field:
>
> 1. date
> 2. time
> 3. filename (including the directory)
>
> The input is produced by a unix oneliner:
>
> find SOMEDIR -type f -iname "*.c" -exec ls -ltr {} \;
>
> SOMEDIR in this case was 1/
>
> two questions:
>
> 1. Can you suggest a oneliner that outputs just what I need?
> 2. Can you suggest a nice clean Perl code that can take two strings of the form
> Oct 29 23:36
> and can perform the following operations:
>
> recent(@date_time_strings)
> should return one string from the list which is the more recent date_time
> or undef if the list is empty. You can assume the strings are of the form
> of the date_time you get from 'ls -l' like the examples above.
>
> recent(@date_time_strings,$deadline_date_time_string)
> should return one string most recent to the deadline but not after the deadline.
> undef should be returned if no such string exists.
>
>
> Thanks.
>
>
>
>
----------------------------------------------------------------------
Shlomi Fish shlomif at vipe.technion.ac.il
Home Page: http://t2.technion.ac.il/~shlomif/
He who re-invents the wheel, understands much better how a wheel works.
More information about the Perl
mailing list