On Tue, 20 Jan 2004, Bastian Angerstein wrote:
>
> I got the following Problem:
>
> My hashkeys looks like "number:string" .
>
> For example "10530:fileparameter-sa1"
> "10529:fileparameter-mv1"
> "10531:fileparameter-tx4"
>
> (without the " signs...)
>
> I would like to sort the hashkeys by the number
> before the doublepoint.
Well I dreamt up a hash a la DATA statement and tried this
-----------------------------------
#!/usr/bin/perl -w
%h=();
while (<DATA>){
chomp;
@bits=split;
$h{$bits[0]}=$bits[1];
}
foreach $item(sort{$a <=> $b}keys %h){print "$item is $h{item}\n"}
__DATA__
10530:fileparameter-sa1 1002
10529:fileparameter-mv1 1987
10531:fileparameter-tx4 456666
66:fileparameter-tx4 333333
7777777777:fileparameter-tx4 1
7896:fileparameter-tx4 44444
------------------------------------------------
and it produced;
66:fileparameter-tx4 is
7896:fileparameter-tx4 is
10529:fileparameter-mv1 is
10530:fileparameter-sa1 is
10531:fileparameter-tx4 is
7777777777:fileparameter-tx4 is
So maybe that could help you
Owen
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>