Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Removing youngest directory

by steves (Curate)
on Nov 09, 2004 at 21:05 UTC ( #406501=note: print w/ replies, xml ) Need Help??


in reply to Removing youngest directory

Your specific issue is that you're using the <=> operator to compare non-numeric values. Try using cmp instead. Test program to illustrate:

use strict; my @dirs = (qw/11-08-2004 11-10-2004 11-07-2004 11-09-2004/); print "Using <=>:\n", join("\n", sort {$b <=> $a} @dirs), "\n\n"; print "Using cmp:\n", join("\n", sort {$b cmp $a} @dirs), "\n";
produces:
Using <=>: 11-09-2004 11-07-2004 11-10-2004 11-08-2004 Using cmp: 11-10-2004 11-09-2004 11-08-2004 11-07-2004

Your directories will lexically sort as is, but they are not numbers since they have dashes.


Comment on Re: Removing youngest directory
Select or Download Code
Re^2: Removing youngest directory
by tc1364 (Beadle) on Nov 09, 2004 at 21:11 UTC
    Thank you... the cmp is much better. As far as the quotes, I will need to remember this. the reason why i have been doing this is because this was the way i was taught.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://406501]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-09-03 03:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (35 votes), past polls