* Mok T.Y.-r15382 <[EMAIL PROTECTED]> [2002-04-15 15:14 +0200]:
> I need some help in converting strings that contain numbers back into
> numeric form. 

No need to convert: Perl doesn't differ between numbers and strings.
Yes, this is completely unlike C, and normally it works as expected.
Just in very few cases you need to choose a sorting algorithm or force
numeric by adding 0 to a putative string.

> Apparently, when I sort string formatted number, the
> arrangement was according to alphanumeric order (eg. 1,
> 10,11,2,20,21,3,30... )

use the right comparator:
        <=> to sort numerically (1,2,10,...) and
        cmp to sort alphabeteically (1,10,2,...).

Examples:
        @sorted_numerically    = sort {$a <=> $b} @mylist;
        @sorted_alphabetically = sort {$a <=> $b} @mylist;

perldoc -f sort for more examples.

-- 
Johannes Franken
 
Professional unix/network development
mailto:[EMAIL PROTECTED]
http://www.jfranken.de/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to