Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!swrinde!ucsd!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal L. Schwartz) Newsgroups: comp.lang.perl Subject: Re: Just Another Perl Novice Keywords: sort Message-ID: <1991Mar29.032459.8925@iwarp.intel.com> Date: 29 Mar 91 03:24:59 GMT References: <3539@inews.intel.com> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal L. Schwartz) Distribution: comp Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 47 In-Reply-To: dmccart@morticia.intel.com (D. J. McCarthy ~) In article <3539@inews.intel.com>, dmccart@morticia (D. J. McCarthy ~) writes: | - Is it the version I'm running? It does look mighty old. Yes. | - How can I do what I want to do without getting a new version? (It's | not that I don't want to, or that I don't have permission on the 490; | it's just that uunet doesn't like me.) Replace it with | #!/usr/local/bin/perl | | sub bynumber { $b <=> $a; } sub bynumber { $b - $a; } ## this works for *integers* only | $thisdie = 1; | while ($thisdie <= 4) { | @rolls[$thisdie] = int(rand(6)) + 1; $rolls[$thisdie] = int(rand(6)) + 1; | } | | @sortrolls = sort bynumber @rolls; @foo[] gives you an array of variables, where $foo[] gives you a scalar variable. Personally, I'd code that more like: sub bynumber { $b - $a; } @rolls = (); for (1..4) { push(@rolls, int(rand(6)) + 1; } @rolls = sort bynumber @rolls; print "Just another Perl hacker," -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/