Re: question about sort()
From: Jim Gibson (jgibson_at_mail.arc.nasa.gov)
Date: 03/04/05
- Next message: Joe Smith: "Re: Trouble with $key to HASH when Numeric"
- Previous message: rasdj_at_frontiernet.net: "Re: array executes only first"
- In reply to: Wiseguy: "question about sort()"
- Next in thread: mazzawi_at_gmail.com: "Re: question about sort()"
- Reply: mazzawi_at_gmail.com: "Re: question about sort()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 04 Mar 2005 10:40:50 -0800
In article <4227e426$1_2@127.0.0.1>, Wiseguy <noone@uber.usachoice.net>
wrote:
> OK. I need to sort a list and I have the following code
>
> @L=(35,10,0,27,100,-4);
> sub numeric { $A <=> $b; }
> @L=sort numeric @L;
>
> The only reference I have is an ancient Oreilly book on Perl 4.
> does sort() actually sort the operand list or only return a sorted list?
> Is it safe to use the source operand as the return value of sort() as well?
One way to find out is try it. If you run the above code, you will get
some peculiar results. If you want to know why, put 'use strict;' at
the beginning of your program.
Another way is to read the documentation that comes with Perl
installations:
perldoc -f sort
although in this case that documentation does not explicitly say that
it sorts or doesn't sort the original array. So I refer you to method
1.
There are newer O'Reilly books on Perl. The curre
Good luck.
FYI: this newsgroup is defunct. Try comp.lang.perl.misc in the future
(but be sure to read the guidelines for that group before posting, as
you have violated more than one of the strictures for posting to that
group).
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
- Next message: Joe Smith: "Re: Trouble with $key to HASH when Numeric"
- Previous message: rasdj_at_frontiernet.net: "Re: array executes only first"
- In reply to: Wiseguy: "question about sort()"
- Next in thread: mazzawi_at_gmail.com: "Re: question about sort()"
- Reply: mazzawi_at_gmail.com: "Re: question about sort()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|