LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-23-2014, 05:52 PM   #1
laurel
LQ Newbie
 
Registered: Dec 2014
Posts: 3

Rep: Reputation: Disabled
sorting in perl


I want to convert code1 to code2 but I couldn't sort


<CODE1>
foreach my $str(sort keys %count) {
print Output "$str $count{$str}\n";
}

<CODE2>
while (my $str = each %count){
}
continue{
print Output "$str $count{$str}\n";
}

Last edited by laurel; 12-23-2014 at 06:05 PM.
 
Old 12-27-2014, 09:19 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
have you tried:
while (my $str = each sort keys %count)
??
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting list in perl rocky9 Programming 3 04-16-2012 06:56 AM
having difficulty sorting hash alphabetically by value in PERL Joseph Schiller Programming 11 01-06-2009 11:58 AM
Help with pattern matching, sorting data with awk/gawk or perl placem Programming 2 09-11-2008 02:26 PM
Perl: Sorting by occurrence of specific character Poetics Programming 5 09-26-2007 04:46 PM
Perl Array Sorting craig467 Programming 8 10-02-2006 05:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration