473,379 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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 1752
<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kamilche | last post by:
I've written a generic sort routine that will sort dictionaries, lists, or tuples, either by a specified key or by value. Comments welcome! import types def sort(container, key = None,...
4
by: its me | last post by:
Let's say I have a class of people... Public Class People Public Sex as String Public Age as int Public Name as string end class And I declare an array of this class...
7
by: Stuart | last post by:
The stl::sort() that comes with Dev Studio 6 is broken (it hits the degenerate case in a common situation). I have a replacement. I would like to globally do "using namespace std; except use my...
19
by: Derek Martin | last post by:
Hi there, I have been playing with sorting my arraylist and having some troubles. Maybe just going about it wrong. My arraylist contains objects and one of the members of the object is 'name.' I...
23
by: Brian Blais | last post by:
Hello, I have two lists, one with strings (filenames, actually), and one with a real-number rank, like: A= B= I'd like to sort list A using the values from B, so the result would be in...
48
by: Alex Chudnovsky | last post by:
I have come across with what appears to be a significant performance bug in ..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same data. Same data on the same CPU gets sorted a...
3
by: John Nagle | last post by:
Are weak refs slower than strong refs? I've been considering making the "parent" links in BeautifulSoup into weak refs, so the trees will release immediately when they're no longer needed. In...
7
by: lukertin | last post by:
I have a 2-D array stored as an object, when i go to call up the array using my $testvar = @ {$self->Peptides}; it gives me the error Can't use string ("0") as an ARRAY ref while "strict...
5
by: _dee | last post by:
I'm working on a port of a legacy app originally written in C. Data was compacted into bit fields. Are there any sites or books that cover optimized handling of this type of data? I'd need to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.