sorting of arrays
I understand that perl desides how it stores data in an array. does it make sense for me to ... @sorted = sort @list;
RE: sorting of arrays
As default it assumes ascii (alphanumeric data). So if you have only numeric data then you need to change to @sorted = sort {$a <=> $b} @list; which would sort numerically if needed otherwise will sort as you want. Wags ;) -Original Message- From: Quincy Ntuli [mailto:[EMAIL PROTECTED]] Sent: Tuesday, September 04, 2001 05:16 To: [EMAIL PROTECTED] Subject: sorting of arrays I understand that perl desides how it stores data in an array. does it make sense for me to ... @sorted = sort @list; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: sorting of arrays
on Tue, 04 Sep 2001 12:15:37 GMT, Quincy Ntuli wrote: > I understand that perl desides how it stores data in an array. Perl doesn't, you do. Data in an array is indexed by an integer. You, the programmer, choses at which position you put your data: $array[0] = 0; $array[1] = 1; Or, by using push, you take the next available position: push @array, 3; is the same as $array[2] = 2; Perl *does* decide in which order it iterates over the keys of a hash. -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: sorting of arrays
Felix Geerinckx wrote: > (...) > Or, by using push, you take the next available position: > > push @array, 3; > > is the same as > $array[2] = 2; > (...) Maybe a typo? push @array, 3; should be the same as $array[2] = 3; -- Zanardi2k2 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: sorting of arrays
on Thu, 05 Sep 2002 08:46:08 GMT, [EMAIL PROTECTED] (Zanardi2k2) wrote: > Felix Geerinckx wrote: > >> push @array, 3; >> >> is the same as >> $array[2] = 2; >> (...) > > > Maybe a typo? > > push @array, 3; > > should be the same as > > $array[2] = 3; Indeed. Thanks for spotting it. -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]