sort and Sub Refs

Discussion in 'Perl' started by Guest, Jan 3, 2004.

  1. Guest

    Guest 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!
    Guest, Jan 3, 2004
    #1
    1. Advertising

  2. Guest

    Guest Guest

    <> 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.
    Guest, Jan 3, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Nagle
    Replies:
    3
    Views:
    298
    John Nagle
    Feb 25, 2007
  2. Ben
    Replies:
    2
    Views:
    883
  3. Sub-sort after sort

    , Nov 2, 2007, in forum: Python
    Replies:
    5
    Views:
    767
    Paul Hankin
    Nov 3, 2007
  4. Lawrence D'Oliveiro

    Death To Sub-Sub-Sub-Directories!

    Lawrence D'Oliveiro, May 5, 2011, in forum: Java
    Replies:
    92
    Views:
    2,021
    Lawrence D'Oliveiro
    May 20, 2011
  5. Yakov
    Replies:
    2
    Views:
    93
    Ben Morrow
    Aug 10, 2008
Loading...

Share This Page