Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting structure with 2 keys 1

Status
Not open for further replies.

dmazzini

Programmer
Jan 20, 2004
480
US
I have perl structure:


Code:
@{$DATA->{RNCID}{$rncid}{$wbtsid}}

$rncid and $wbtsid (keys) are numeric and I would like to sort by $rncid and then for bts id.

I tried:

Code:
foreach $rncid (sort {$a cmp $b}(keys %{$DATA->{RNCID}})){
	      foreach $wbtsid (sort {$a cmp $b} keys %{$DATA->{RNCID}{$rncid}}){		      
	               print "@{$DATA->{RNCID}{$rncid}{$wbtsid}}\n";
       }
}

It sorts per rncid, but not for wbtsid

Any ideas

dmazzini
GSM/UMTS System and Telecomm Consultant

 
Code:
It does not work as well

{$a <=>$b}

dmazzini
GSM/UMTS System and Telecomm Consultant

 
At first glance, I don't see anything wrong with your code.

Just in case...
Code:
foreach my $rncid (sort keys %{$DATA->{RNCID}}) {
	foreach my $btsid (sort keys %{$DATA->{RNCID}{$rncid}}) {
		print "RNC: $rncid - BTS: $btsid\n";
	}
}
What do the RNC and BTS ids look like? Are they strictly numeric or do they have other characters as well?
 
Hi

I had make a mistake in my script, coming from a regex..:

Code:
($rncid,$wbtsid)=($2,$3);
push (@{$DATA->{RNCID}{$rncid}{$wbtsid}},$intext."\n");

Correct is
Code:
($rncid,$wbtsid)=($2,$4);
push (@{$DATA->{RNCID}{$rncid}{$wbtsid}},$intext."\n");

Thanks rharsh for your help


dmazzini
GSM/UMTS System and Telecomm Consultant

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top