in reply to Helping Beginners
Whatever the level of the person, I've found that a lot of the time two or three solutions can be the best. They'll pick the one they are most comfortable with, but at the same time (*hopefully*) be intrigued by the other possibilites. Then you can forward them on to the appropriate documentation and let them play.
The other reason I posted was because I couldnt see why you are doing four steps, instead of three or even what I prefer two. I played around with this for a bit and came up with three variations, all simpler (at least to me).
My first solution was a straight transformation of your two stage prepare with a one stage prepare, and I cheated and lost the call to trim, using m// in list context.
My next thought was that the date format sucked, and that maybe the sort logic could be simplified in one go, also that I probably would end up splitting it at some point so I might as well return a list of the parts. A bit more complex regex might also be nice.@data = map { $_->[0] } sort { $a->[3] <=> $b->[3] # YY ||$a->[1] <=> $b->[1] # MM ||$a->[2] <=> $b->[2]} # DD map { [ m!^\s*(\D*(\d+)/(\d+)/(\d+)(?: [\d.]+)*)\s*$! ] } @idata; # 0 1MM 2DD 3YY
But then I decide that I might not want to do that, and I might want it as fast as possible. In which case I wouldn't use an ST but a GRT@data = sort { $a->[1] cmp $b->[1] } # Sort by YYYY/MM/DD map { my @p=m!^\s*([A-Za-z]+)\s+ # alpha word (\d+)/(\d+)/(\d+) # date MM DD YY (?:\s+([\d.]+)) # Substitute Number regex he +re (?:\s+([\d.]+)) # .. (?:\s+([\d.]+)) # .. (?:\s+([\d.]+))!x; # Comments please # Fix the date if this is still in use in 2050... splice @p,1,3,sprintf("%04d/%02d/%02d", ($p[3]>50 ? $p[3]+1900 : $p[3]+2000), @p[1,2]); # it deserves to produce incorrect results, after all # 2 digit dates is madness \@p} # return the fixed array @idata;
The point being that these are the kind of ideas that I would probably show an interested colleague if I was asked.@data = map {substr($_,3)} sort #lexicographical representation of the date map { m!^\s*(\D*(\d+)/(\d+)/(\d+)(?: [\d.]+)*)\s*$! && pack ("CCCA*",$4,$2,$3,$1)} @idata;
Anyway Ovid thanks for the thought, and for provoking the thoughts you did, (japhy++), I had a good time with this one.
BTW: Im too tired now, but tomorrow I'll update this space with a link to the excellent article on sorting and the Guttman Rosler Transform (do a Super Search until then :)
Yves / DeMerphq
--
Have you registered your Name Space?
|
---|