Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

How about just counting...

by bastard (Hermit)
on Jul 28, 2000 at 11:31 UTC ( [id://24809]=note: print w/replies, xml ) Need Help??


in reply to Count backwards from Z...
in thread Sorting on Section Numbers

Damn, so I don't know how to use this thing... (managed to post anon and mess up the present) Here it is (hopefully the corect way...)
-------------------------------------------------------------- #!/usr/bin/perl @list = ("1", "3.4b.4", "2", "15", "123", "2.2", "2.13", "2.1.7", "311 +2", "3.4a", "1.5.32.1", "3.4.1", "3.1.5", "3.4b.1"); foreach $section (@list) { my @subSections = split (/\./, $section); for (my $x=0; $x <= $#subSections; $x++) { if ($maxdigit[$x] < length($subSections[$x])) { $maxd +igit[$x] = length($subSections[$x]); } } } my @paddedList = (); foreach $section (@list) { my @subSections = split (/\./, $section); my $paddedSection = ""; for (my $x=0; $x <= $#subSections; $x++) { my $padding = ""; for(my $y = 0; $y < $maxdigit[$x]-length($subSections[ +$x]); $y++) { $padding .= "0"; } $paddedSection .= "$padding$subSections[$x]."; } $paddedSection =~ s/\.$//; push (@paddedList, $paddedSection); } @sortedList = sort @paddedList; foreach $section (@sortedList) { my @subSections = split (/\./, $section); my $unPaddedSection = ""; for (my $x=0; $x <= $#subSections; $x++) { $subSections[$x] =~ s/^0*//; $unPaddedSection .= "$subSections[$x]."; } $unPaddedSection =~ s/\.$//; push (@unPaddedList, $unPaddedSection); } foreach $li (@unPaddedList) { print "$li\n"; } --------------------------------------------------------------

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-03-28 19:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found