469,603 Members | 2,098 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,603 developers. It's quick & easy.

sort and Sub Refs

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!
Jul 19 '05 #1
1 1620
<je*****@loois.com> wrote in message
news:ZQwJb.141322$ss5.133444@clgrps13...
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.
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Kamilche | last post: by
4 posts views Thread by its me | last post: by
7 posts views Thread by Stuart | last post: by
19 posts views Thread by Derek Martin | last post: by
23 posts views Thread by Brian Blais | last post: by
48 posts views Thread by Alex Chudnovsky | last post: by
3 posts views Thread by John Nagle | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.