ST

ST

am 26.11.2007 17:28:16 von TekWiz

I'm trying to make the sort criteria for an ST variable. If I preset a
variable to the required information as in:

my $SortC = "$a->[$FIELD1] <=> $b->[$FIELD1]
||
$a->[$FIELD25] cmp $b->[$FIELD25]";

and then set the ST to :

my @SA = map { $_->[0] }
sort { $SortC }
map { [$_, split(/\|/)] } @A;

It will return Sort does not return a numeric value.; However, if I
statically set the sort strings above it works. Any ideas on how to
make it variable "on the fly".

Re: ST

am 26.11.2007 17:42:08 von jurgenex

tekwiz wrote:
> I'm trying to make the sort criteria for an ST variable.

Stupid question: what is an ST variable?
I only recall ST being used as in Atari ST but never in connection with a
variable.

jue

Re: ST

am 26.11.2007 18:19:39 von Uri Guttman

>>>>> "t" == tekwiz writes:

t> I'm trying to make the sort criteria for an ST variable. If I preset a
t> variable to the required information as in:

t> my $SortC = "$a->[$FIELD1] <=> $b->[$FIELD1]
t> ||
t> $a->[$FIELD25] cmp $b->[$FIELD25]";


why are those quotes there? where did you ever get the idea that you can
just pass around a string of code and have it magically execute?

t> and then set the ST to :

t> my @SA = map { $_->[0] }
t> sort { $SortC }

that is sorting based on a fixed string which is always true. your sort
results will have nothing to do with the data.

if you want to make an ST sort (or the faster GRT) use Sort::Maker. you
can even print out the generated sort code so you can learn from it.

uri

--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org

Re: ST

am 26.11.2007 18:50:06 von Michele Dondi

On Mon, 26 Nov 2007 08:28:16 -0800 (PST), tekwiz
wrote:

>I'm trying to make the sort criteria for an ST variable. If I preset a
>variable to the required information as in:
>
>my $SortC = "$a->[$FIELD1] <=> $b->[$FIELD1]
> ||
> $a->[$FIELD25] cmp $b->[$FIELD25]";

Huh?!? You're putting a STRING in $SortC

>
>and then set the ST to :
>
>my @SA = map { $_->[0] }
> sort { $SortC }

You're somehow expecting the code that "by pure chance" happens to be
in $SortC to be eval()uated. That's not the case. Do a favour to
yourself and re-read

perldoc -f sort


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^ ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

Re: ST

am 26.11.2007 19:50:08 von it_says_BALLS_on_your forehead

On Nov 26, 11:42 am, "Jürgen Exner" wrote:
> tekwiz wrote:
> > I'm trying to make the sort criteria for an ST variable.
>
> Stupid question: what is an ST variable?
> I only recall ST being used as in Atari ST but never in connection with a
> variable.
>


You may have already figured this out by now, but in case you haven't:
ST in this context refers to Schwartzian Transform.

Re: ST

am 26.11.2007 20:36:54 von jurgenex

nolo contendere wrote:
> On Nov 26, 11:42 am, "Jürgen Exner" wrote:
>> tekwiz wrote:
>>> I'm trying to make the sort criteria for an ST variable.
>>
>> Stupid question: what is an ST variable?
>> I only recall ST being used as in Atari ST but never in connection
>> with a variable.
>
> You may have already figured this out by now, but in case you haven't:
> ST in this context refers to Schwartzian Transform.

No, I didn't. Thanks

jue

Re: ST

am 26.11.2007 20:37:07 von Paul Lalli

On Nov 26, 11:28 am, tekwiz wrote:
> I'm trying to make the sort criteria for an ST variable. If I preset a
> variable to the required information as in:
>
> my $SortC = "$a->[$FIELD1] <=> $b->[$FIELD1]
> ||
> $a->[$FIELD25] cmp $b->[$FIELD25]";
>
> and then set the ST to :
>
> my @SA = map { $_->[0] }
> sort { $SortC }
> map { [$_, split(/\|/)] } @A;
>
> It will return Sort does not return a numeric value.; However, if I
> statically set the sort strings above it works. Any ideas on how to
> make it variable "on the fly".

Why people can't just answer the question, I will never understand.
Three separate responses. One says "What's an ST Variable", when it's
perfectly obvious from the context. One says "That doesn't make
sense, use the module I wrote!!!". One says "That doesn't make sense,
go read the documentation!".

Folks, the OP KNOWS it doesn't make sense. He's saying this is what
he tried, it doesn't work, he knows it doesn't work. He's asking how
to accomplish his goal.

To the OP: you need to make what you are calling the "ST Variable" be
a subroutine reference, not a string. Strings do not get evaluated as
Perl code unless you very specifically tell them to (usually by way of
the evil eval() function). The argument to sort() is a subroutine to
execute, not a string:

$ perl -MData::Dumper -le'
my @foo = ( "0 1", "0 2", "1 5", "1 2", "0.5 3" );
my $sort_sub = sub {
$a->[0] <=> $b->[0] ||
$a->[1] <=> $b->[1]
};
my @SA = map { $_->[2] }
sort $sort_sub
map { [(split / /, $_), $_] } @foo;
print Dumper(\@SA);
'
Results:
$VAR1 = [
'0 1',
'0 2',
'0.5 3',
'1 2',
'1 5'
];


Hope this helps,
Paul Lalli

Re: ST

am 26.11.2007 20:45:43 von it_says_BALLS_on_your forehead

On Nov 26, 2:37 pm, Paul Lalli wrote:
> On Nov 26, 11:28 am, tekwiz wrote:
>
>
>
> > I'm trying to make the sort criteria for an ST variable. If I preset a
> > variable to the required information as in:
>
> > my $SortC = "$a->[$FIELD1] <=> $b->[$FIELD1]
> > ||
> > $a->[$FIELD25] cmp $b->[$FIELD25]";
>
> > and then set the ST to :
>
> > my @SA = map { $_->[0] }
> > sort { $SortC }
> > map { [$_, split(/\|/)] } @A;
>
> > It will return Sort does not return a numeric value.; However, if I
> > statically set the sort strings above it works. Any ideas on how to
> > make it variable "on the fly".
>
> Why people can't just answer the question, I will never understand.
> Three separate responses. One says "What's an ST Variable", when it's
> perfectly obvious from the context. One says "That doesn't make
> sense, use the module I wrote!!!". One says "That doesn't make sense,
> go read the documentation!".
>

As an aside, I benefited from reading the documentation on sort,
specifically, the following passage:

Because "<=>" returns "undef" when either operand is
"NaN" (not-a-number), and because "sort" will
trigger a fatal error unless the result of a
comparison is defined, when sorting with a
comparison function like "$a <=> $b", be careful
about lists that might contain a "NaN". The
following example takes advantage of the fact that
"NaN != NaN" to eliminate any "NaN"s from the input.

@result = sort { $a <=> $b } grep { $_ == $_ }
@input;


Applying this appropriately seems like a great way to logically
determine whether the '<=>' or 'cmp' operator should be used on
various sets of data. I think this is much better than trying to use a
variety of regexes to test whether values are numeric, and is even
better than using Test::Numeric.

Of course, others may disagree...

Re: ST

am 26.11.2007 21:01:07 von TekWiz

On Nov 26, 2:45 pm, nolo contendere wrote:
> On Nov 26, 2:37 pm, Paul Lalli wrote:
>
>
>
> > On Nov 26, 11:28 am, tekwiz wrote:
>
> > > I'm trying to make the sort criteria for an ST variable. If I preset a
> > > variable to the required information as in:
>
> > > my $SortC = "$a->[$FIELD1] <=> $b->[$FIELD1]
> > > ||
> > > $a->[$FIELD25] cmp $b->[$FIELD25]";
>
> > > and then set the ST to :
>
> > > my @SA = map { $_->[0] }
> > > sort { $SortC }
> > > map { [$_, split(/\|/)] } @A;
>
> > > It will return Sort does not return a numeric value.; However, if I
> > > statically set the sort strings above it works. Any ideas on how to
> > > make it variable "on the fly".
>
> > Why people can't just answer the question, I will never understand.
> > Three separate responses. One says "What's an ST Variable", when it's
> > perfectly obvious from the context. One says "That doesn't make
> > sense, use the module I wrote!!!". One says "That doesn't make sense,
> > go read the documentation!".
>
> As an aside, I benefited from reading the documentation on sort,
> specifically, the following passage:
>
> Because "<=>" returns "undef" when either operand is
> "NaN" (not-a-number), and because "sort" will
> trigger a fatal error unless the result of a
> comparison is defined, when sorting with a
> comparison function like "$a <=> $b", be careful
> about lists that might contain a "NaN". The
> following example takes advantage of the fact that
> "NaN != NaN" to eliminate any "NaN"s from the input.
>
> @result = sort { $a <=> $b } grep { $_ == $_ }
> @input;
>
> Applying this appropriately seems like a great way to logically
> determine whether the '<=>' or 'cmp' operator should be used on
> various sets of data. I think this is much better than trying to use a
> variety of regexes to test whether values are numeric, and is even
> better than using Test::Numeric.
>
> Of course, others may disagree...

Thanks for all the replies. I don't have to worry about the numeric/
text constructs because I know by the way I defined the field names
what they are. My problem is still trying to define the sort criteria
because I have variable amount of fields to compare of either type of
compare. In other words, in some cases, there might be only one field
to compare in other cases more than one. How to define that sort
criteria, for maximum flexibility.

Re: ST

am 26.11.2007 23:11:37 von Jim Gibson

In article
,
tekwiz wrote:

..
>
> Thanks for all the replies. I don't have to worry about the numeric/
> text constructs because I know by the way I defined the field names
> what they are. My problem is still trying to define the sort criteria
> because I have variable amount of fields to compare of either type of
> compare. In other words, in some cases, there might be only one field
> to compare in other cases more than one. How to define that sort
> criteria, for maximum flexibility.

Read the documentation on sort. Your sort subroutine can be as complex
as you can make it. The only restrictions are that it must be stable:
given two array elements, the routine must always return the same value
for those elements. Otherwise, the sort will be unstable and your
results will be undefined.

The other restriction is that your sort subroutine is only passed two
arguments: elements of the array you are trying to sort. So if you need
to reference other data, you need to use information accessible given
the elements: e.g., global variables or hashes using the elements as
keys.

--
Jim Gibson

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Re: ST

am 27.11.2007 12:22:34 von Michele Dondi

On Mon, 26 Nov 2007 10:50:08 -0800 (PST), nolo contendere
wrote:

>> Stupid question: what is an ST variable?
>> I only recall ST being used as in Atari ST but never in connection with a
>> variable.
>>
>
>
>You may have already figured this out by now, but in case you haven't:
>ST in this context refers to Schwartzian Transform.

He did figure it out, just to point out that there's no such a thing
as a "Schwartzian Transform variable" that one can make sense of.


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^ ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

Re: ST

am 27.11.2007 12:26:28 von Michele Dondi

On Mon, 26 Nov 2007 11:37:07 -0800 (PST), Paul Lalli
wrote:

>sense, use the module I wrote!!!". One says "That doesn't make sense,
>go read the documentation!".
>
>Folks, the OP KNOWS it doesn't make sense. He's saying this is what
>he tried, it doesn't work, he knows it doesn't work. He's asking how
>to accomplish his goal.

Well I just cannot hope to concoct up stuff that vaguely seems like
valid code and hope it to work. That kind of "not making sense" is the
one that acquaintance with some basic Perl would make sense of. Thus
reading the docs is highly recommended. If after having done so one
can't still make sense of it, then it would be worth asking, perhaps a
more interesting question.


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^ ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

Re: ST

am 27.11.2007 12:41:13 von Michele Dondi

On Mon, 26 Nov 2007 11:37:07 -0800 (PST), Paul Lalli
wrote:

>perfectly obvious from the context. One says "That doesn't make
>sense, use the module I wrote!!!". One says "That doesn't make sense,

Hehe, I suppose uri's epitaph may be:

our @uri=(make_sorter qw/GRT no_case/)->(slurp 'uri');


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^ ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

Re: ST

am 28.11.2007 15:51:35 von TekWiz

On Nov 27, 6:41 am, Michele Dondi wrote:
> On Mon, 26 Nov 2007 11:37:07 -0800 (PST), Paul Lalli
>
> wrote:
> >perfectly obvious from the context. One says "That doesn't make
> >sense, use the module I wrote!!!". One says "That doesn't make sense,
>
> Hehe, I suppose uri's epitaph may be:
>
> our @uri=(make_sorter qw/GRT no_case/)->(slurp 'uri');
>
> Michele
> --
> {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
> (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^ > .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER > 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

Last reply. Final solution is as follows:

Created specific sort subs for each different report type needed. The
code will detect if a sort sub is written and use it if it is; else,
it does a UNIX shell sort. During the test data, I have approx.
120,000 - 877 byte records of approx. 85 fields to sort and sorting on
4 of them, some text, some numeric. With the UNIX sort, it takes 1:08.
With the Perl sort, it takes 38 seconds. Thanks for your help.