CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Fun With Perl: Perl Quizzes - Learn Perl the Fun Way:
Scope

 



Cure
User

Aug 13, 2000, 10:25 PM

Post #1 of 3 (19169 views)
Scope Can't Post

package Sort;
sub cure
{ $b <=> $a }

package Other;
@new = sort Sort::cure 5, 2, 4, 8;

Whats the VALUE of @new and explain how @new obtained those VALUES


Cure


Cameron
Deleted

Aug 14, 2000, 1:40 PM

Post #2 of 3 (19169 views)
Re: Scope [In reply to] Can't Post

The @new array is left unchanged at
5, 2, 4, 8;
How? I don't have my books handy, but i think it goes something like this.

First the call is made to Sort::cure, where
$a and $b are package global variables. These should be qualified with the package name of the caller, since the sort routine is not in the same package as the caller
Since $a and $b are out of scope, the subroutine returns '0' for each call.

Then sort compares the values returned from
Sort::cure, and since they are all '0', the order remains unchanged.

This populates the @new array with the unchanged list of values.


Cameron



Cure
User

Sep 13, 2000, 8:30 AM

Post #3 of 3 (19169 views)
Re: Scope [In reply to] Can't Post

Cameron your right, good job..


Cure

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives