sort and Sub Refs

G

Guest

Consider the following almost pseudo example:

# main.pl
package main;
require other;

sub mysort() {
#* 1. sort algo
}

# other.pm
package other;

# an object in a class
sub new() { # etc }
sub setusersort() {
my $this = shift( @_ );
$this->{ 'UserSort' } = shift( @_ );
}

sub sort_input()
{
#* 2. call $this->{ 'UserSort' }
}

k so now considering all that. I'm am perplexed. I can pragmatically get my
examples (I've performed various mutations on code) to compile without
warning (-w) and use strict shows no errors. My output is not sorted
however. The parameters (instead of the globals $a and $b) are passed to
mysort(). How do I 'return' the appropriate value? I've tried implicitly and
explicitly defining a return value. 99% of the time the function returns
'1'. I don't get it and my mission to find an example that does kinda what I
have has been fruitless.

Much thanks to any light one can shed... bring halogen or indiglo!
 
G

Guest

Consider the following almost pseudo example:

# main.pl
package main;
require other;

sub mysort() {
#* 1. sort algo
}

# other.pm
package other;

# an object in a class
sub new() { # etc }
sub setusersort() {
my $this = shift( @_ );
$this->{ 'UserSort' } = shift( @_ );
}

sub sort_input()
{
#* 2. call $this->{ 'UserSort' }
}

k so now considering all that. I'm am perplexed. I can pragmatically get my
examples (I've performed various mutations on code) to compile without
warning (-w) and use strict shows no errors. My output is not sorted
however. The parameters (instead of the globals $a and $b) are passed to
mysort(). How do I 'return' the appropriate value? I've tried implicitly and
explicitly defining a return value. 99% of the time the function returns
'1'. I don't get it and my mission to find an example that does kinda what I
have has been fruitless.

Much thanks to any light one can shed... bring halogen or indiglo!

Well it turned out that I was using a version of Perl who's 'sort' didn't
support the passing of arguments to a sub. So in fixing it I merely have to
define the 'user sort' using '$PackageName:a' to reference the globals in
the containing package.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top