in reply to sorting objects

Two notes:
  1. sort can take a subname, so a simple sort netFetObj::fetSort @list looks cleaner than your construct.
  2. if you don't use a prototyped sort sub, $a and $b are globals in package something_else. That means you should refer to them as $something_else::a and $something_else::b inside fetSort.
To summarize:
package netFetObj; sub fetSort { print " ######### A = $something_else::a \n"; print " ######### B = $something_else::b \n"; my $ftA = $something_else::a->{"fet"}; my $ftB = $something_else::b->{"fet"}; $fetType->{$ftA} <=> $fetType->{$ftB} } package something_else; foreach my $fetOBJ ( sort netFetObj::fetSort @{ $OBJ->{"fets"} } ) + { buildFet($FH,$fetOBJ,$OPT); }

Replies are listed 'Best First'.
Re^2: sorting objects
by Anonymous Monk on Jun 23, 2006 at 01:33 UTC

    doh! i feel really silly. of course, the variables would be in the namespace of the caller.

    i had tried various combinations of & and $ on the sort routine. little did i realize that NO symbols are needed!

    yes, i need to use a prototyped sort sub as many other packages will call this.

    BTW, i also changed the hash access to a method

    my $ftA = $_[0]->fet(); my $ftB = $_[1]->fet();

    this looks cleaner too!

    thanks again...

    Formatting and code tags added by GrandFather