in reply to How do I sort by certain parts of a filename?

Well, a split using '_' will get you "Date1", "Date2" and "type.asp", the last you can probably drop. From there, it's a rather easy (!) application of sort:
# this searches on Date1 my @sorted_list = sort { ${split(/_/,$a)}[0] cmp ${split(/_/,$b)}[0] } @list; # [0] is Date1, [1] is Date2, [2] is type.asp
You could also apply the so called Schwartian Transform if your Dates are not directly compariable and need a special function:
my @sorted_list = map { $_[0] } sort { date_compare($a[1],$b[1]) } # [1] is Date1, [2] is Date2, [3] is the type.asp map { [ $_, split /_/ ] } @list;

Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Replies are listed 'Best First'.
Re: How do I sort by certain parts of a filename?
by cLive ;-) (Prior) on May 10, 2001 at 03:36 UTC
    Hmmm, I don't think you can assume anything about the date unless you see examples. Date could be in many different formats.

    Unless actual example and type of sort requested is posted by wstarrs, I don't think we can be that specific :)

    .02

    cLive ;-)

Re: Re: How do I sort by certain parts of a filename?
by jeroenes (Priest) on May 10, 2001 at 09:46 UTC
    Masem wrote:
    ${split(/_/,$b)}[0] }
    To be certain, I tried it, but it doesn't give me the first field of a split. Did you mean:
    [split /_/, $b]->[0]
    ?

    (This is what I usually do, but maybe there is a better Way out there....)

    Jeroen
    "We are not alone"(FZ)

      Even shorter (and faster) is: (split /_/, $b)[0]

              - tye (but my friends call me "Tye")
        That shall learn me to pay attention when doing print some_expr....

        print (split)[0]; failed on me, but of course I should have tested print +(split)[0];. Aargg!

        Jeroen
        "We are not alone"(FZ)