Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Do you know where your variables are?
 
PerlMonks  

Count backwards from Z...

by Anonymous Monk
on Jul 28, 2000 at 07:26 UTC ( [id://24808]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Sorting on Section Numbers

It may be a bit long, but I know this works. ------------------------------------------------------------- #!/usr/bin/perl @list = ("1", "3.4b.4", "2", "15", "123", "2.2", "2.13", "2.1.7", "3112", "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)) { $maxdigit$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"; } -------------------------------------------------------------

Replies are listed 'Best First'.
How about just counting...
by bastard (Hermit) on Jul 28, 2000 at 07:31 UTC
    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://24808]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.