The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Sort and Unique in Perl deepakwins Shell Programming and Scripting 20 02-11-2008 09:25 PM
sort function in perl DILEEP410 Shell Programming and Scripting 2 09-14-2007 09:03 AM
Perl find::file can I sort the out put Andrek Shell Programming and Scripting 2 12-12-2006 01:19 AM
sort and uniq in perl reggiej Shell Programming and Scripting 4 05-18-2006 11:46 PM
Sort file in perl annececile Shell Programming and Scripting 4 06-21-2002 09:52 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 4.00 average. Display Modes
  #1 (permalink)  
Old 07-10-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,092
perl sort

Hi all,

Say i have a array


Code:
@array=("abc,"a",ab");

I would like to sort them according to the length.

Any idea? thanks in advanced.

i tried below code, but not work.


Code:
sub sort_fun{
 if (length shift(@_) >= length shift(@_) ){
        return 1;
 }
 else{
        return 0;
 }
}

print join (", ",sort{sort_fun($a,$b)} ("abc","a","ab") ."\n";

  #2 (permalink)  
Old 07-10-2008
KevinADC KevinADC is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2008
Posts: 731

Code:
my @array = qw(abc a ab);
@array = sort {length $a <=> length $b} @array;
print "$_\n" for @array;

Closed Thread

Bookmarks

Tags
perl, perl shift, shift, shift perl

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:23 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0