Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have a list of files:
file1
file2
...
file10
...
file20
...
The list can contain any number of file names up to about 1000. I have these names stored in a hash, and use the following code to print the file names:
file1
file10
file11
file2
file20
file3
How do I sort them based on counting order? I don't have access to install any modules that are not already installed on the system, so please don't suggest a module.
Thanks in Advance.
file1
file2
...
file10
...
file20
...
The list can contain any number of file names up to about 1000. I have these names stored in a hash, and use the following code to print the file names:
problem is the the filenames print like this:foreach my $file (sort {$a cmp $b} keys %hash) { print "$key \n"; }
file1
file10
file11
file2
file20
file3
How do I sort them based on counting order? I don't have access to install any modules that are not already installed on the system, so please don't suggest a module.
Thanks in Advance.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Sorting Files with Numbers (natural sort)
by tye (Sage) on Dec 30, 2002 at 15:46 UTC | |
Re: Sorting Files with Numbers
by dragonchild (Archbishop) on Dec 30, 2002 at 15:47 UTC | |
Re: Sorting Files with Numbers
by jdporter (Paladin) on Dec 30, 2002 at 15:56 UTC | |
Re: Sorting Files with Numbers
by BrowserUk (Patriarch) on Dec 30, 2002 at 15:49 UTC | |
by hardburn (Abbot) on Dec 30, 2002 at 17:07 UTC | |
by dmmiller2k (Chaplain) on Dec 31, 2002 at 15:08 UTC | |
Re: Sorting Files with Numbers
by Wonko the sane (Deacon) on Dec 30, 2002 at 16:11 UTC | |
by John M. Dlugosz (Monsignor) on Dec 30, 2002 at 17:07 UTC | |
by Wonko the sane (Deacon) on Dec 30, 2002 at 17:19 UTC | |
by John M. Dlugosz (Monsignor) on Dec 30, 2002 at 17:22 UTC | |
Re: Sorting Files with Numbers
by Anonymous Monk on Jan 01, 2003 at 21:55 UTC | |
Re: Sorting Files with Numbers
by helgi (Hermit) on Jan 02, 2003 at 11:05 UTC |
Back to
Seekers of Perl Wisdom