[29823] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1066 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 26 18:09:42 2007

Date: Mon, 26 Nov 2007 15:09:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 26 Nov 2007     Volume: 11 Number: 1066

Today's topics:
        Help needed regarding RPC::XML return value <darcykahle@gmail.com>
    Re: Help needed regarding RPC::XML return value <glex_no-spam@qwest-spam-no.invalid>
    Re: Help needed regarding RPC::XML return value <ben@morrow.me.uk>
    Re: How to append a file accordingly? <ytlim1@gmail.com>
        performance problem <anon24u@gmail.com>
    Re: performance problem <smallpond@juno.com>
    Re: performance problem <ben@morrow.me.uk>
        Perl usage <kbadinger@gmail.com>
    Re: Perl usage <jurgenex@hotmail.com>
    Re: Perl usage <m@rtij.nl.invlalid>
    Re: Perl usage xhoster@gmail.com
    Re: perldebtut - Perl debugging tutorial <1usa@llenroc.ude.invalid>
    Re: Spidering Hacks <alexxx.magni@gmail.com>
    Re: Spidering Hacks <spamtrap@dot-app.org>
    Re: ST <jurgenex@hotmail.com>
    Re: ST <mritty@gmail.com>
    Re: ST <simon.chao@fmr.com>
    Re: ST <ryoung@medicalpharmacies.com>
    Re: ST <jimsgibson@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 26 Nov 2007 14:14:56 -0800 (PST)
From: Darcy <darcykahle@gmail.com>
Subject: Help needed regarding RPC::XML return value
Message-Id: <0345bb8d-5f13-41aa-98b4-c8571a2cfdcf@r60g2000hsc.googlegroups.com>

I am trying to write an XML-RPC server method in perl using RPC::XML,
and I am having a rather perplexing problem when I attempt to return a
data structure to the caller (a Java app).  I am told that the caller
is expecting an array of structs as the result.

I have tried many things, but have ended up with the same problem.  as
an example, and as an attempt to simplify things, this is what my
method is returning:

      return [({'SELL_LINE_NUMBER' => '1', 'ERROR_CODE' => "0",
'MESSAGE' => "test", 'CURRENT_TOTAL' => "1"})];

This is the error that the Java app is generating when it receives the
response:

ERROR 26 Nov 2007 16:56:50
(org.wh.client.frontend.listener.WHAbstractFrontEndActionListener) -
java.lang.ClassCastException: java.lang.Integer


I have even tried this code snippet:

      my @status;
      my $record;
      $record->{SELL_LINE_NUMBER} = $parts1;
      $record->{ERROR_CODE} = "0";
      $record->{MESSAGE} = "test";
      $record->{CURRENT_TOTAL} = "1";
      push(@status,$record);
      return \@status;

with the same error being generated.  I am at my wit's end trying to
figure out what is going on, and get it working.  I also am not having
much luck finding other discussions of this problem elsewhere on the
internet.

I appreciate any and all help that you can supply.

Darcy


------------------------------

Date: Mon, 26 Nov 2007 16:30:31 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Help needed regarding RPC::XML return value
Message-Id: <474b4908$0$503$815e3792@news.qwest.net>

Darcy wrote:
[...]
> ERROR 26 Nov 2007 16:56:50
> (org.wh.client.frontend.listener.WHAbstractFrontEndActionListener) -
> java.lang.ClassCastException: java.lang.Integer
> 
> 
> I have even tried this code snippet:
> 
>       my @status;
>       my $record;
>       $record->{SELL_LINE_NUMBER} = $parts1;
>       $record->{ERROR_CODE} = "0";
>       $record->{MESSAGE} = "test";
>       $record->{CURRENT_TOTAL} = "1";
>       push(@status,$record);
>       return \@status;
> 
> with the same error being generated.  I am at my wit's end trying to
> figure out what is going on, and get it working.  I also am not having
> much luck finding other discussions of this problem elsewhere on the
> internet.
> 
> I appreciate any and all help that you can supply.

Just a guess..

Why are you quoting 0 and 1?

Given that the exception points to an Integer problem, remove
the quotes so Java will see it as an Integer instead of a string.


------------------------------

Date: Mon, 26 Nov 2007 22:22:48 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Help needed regarding RPC::XML return value
Message-Id: <oitr15-is1.ln1@osiris.mauzo.dyndns.org>


Quoth Darcy <darcykahle@gmail.com>:
> I am trying to write an XML-RPC server method in perl using RPC::XML,
> and I am having a rather perplexing problem when I attempt to return a
> data structure to the caller (a Java app).  I am told that the caller
> is expecting an array of structs as the result.
> 
> I have tried many things, but have ended up with the same problem.  as
> an example, and as an attempt to simplify things, this is what my
> method is returning:
> 
>       return [({'SELL_LINE_NUMBER' => '1', 'ERROR_CODE' => "0",
> 'MESSAGE' => "test", 'CURRENT_TOTAL' => "1"})];
> 
> This is the error that the Java app is generating when it receives the
> response:
> 
> ERROR 26 Nov 2007 16:56:50
> (org.wh.client.frontend.listener.WHAbstractFrontEndActionListener) -
> java.lang.ClassCastException: java.lang.Integer

Just a completely random guess: have you tried using numbers instead of
strings? That is,

    return [{
        SELL_LINE_NUMBER    => 1,  # note absence of quotes
        ERROR_CODE          => 0,
        MESSAGE             => 'test',
        CURRENT_TOTAL       => 1,
    }];

Ben



------------------------------

Date: Mon, 26 Nov 2007 14:24:56 -0800 (PST)
From: Why Tea <ytlim1@gmail.com>
Subject: Re: How to append a file accordingly?
Message-Id: <133888e2-0ad3-4415-a3b7-86bfbd6b7e75@d4g2000prg.googlegroups.com>

On Nov 27, 3:41 am, "Petr Vileta" <sto...@practisoft.cz> wrote:
> Why Tea wrote:
> > On Nov 26, 1:46 pm, "Petr Vileta" <sto...@practisoft.cz> wrote:
>
> >> Maybe this way?
>
> >> if($some_text =~ m/(\r\n|\n|\r)$/s)
> >>     {
> >>     print FH "$some_text";
> >>     }
> >> else
> >>     {
> >>     print FH "\n$some_text";
> >>     }
>
> > Petr, your code checks for white spaces at the end of $some_text, but
> > I was talking about white spaces at the end of the opened file, i.e.
> > open(FH, $some_file)
>
> I assumed that whole file content is in $some_text. When you can read file
> line by line then you can use this
>
> open FH "< $myfile";
> binmode FH; # not need for *nix systems
> seek FH, -2, 2; # seek for last 2 bytes
> my $lastchars = <FH>;
> close FH;
> open FH "< $myfile";
> while (my $row = <FH>)
>     {
>     print $row;
>     }
> close FH;
> print "\n" unless($lastchars =~ m/(\r\n|\n|\r)$/s)
> --

Thanks Petr. The code works fine in detecting \r\n|\n|\r, but it fails
when the $lastchars are just normal characters. What I did was to
append a line of text to the file and I didn't want to have a blank
line if there is already \r\n|\n|\r. I ran your code once, it was OK
but the subsequent runs failed (I expected \n to be printed, but it
didn't).

/Why Tea


------------------------------

Date: Mon, 26 Nov 2007 12:01:13 -0800 (PST)
From: Gizbo <anon24u@gmail.com>
Subject: performance problem
Message-Id: <7b07523c-bd49-45d6-9541-aa4e2af7a258@b15g2000hsa.googlegroups.com>

Hi,

My workstation was recently upgraded to Fedora 8, and this has wreaked
havoc on the performance of my perl application.  I did a profile on
the code and the problem appears to be within Scalar::Util.  The thing
is, I don't know what to do next...  The code below used to take about
2s to run, now it is several minutes!  I use the Class::Std
infrastructure, and that is generating the 320k calls to refaddr, but
the same code producing the same number of calls runs in a couple
seconds on an older workstation.

Any suggestions?

[ollivier@samba anc]$ dprofpp
Total Elapsed Time = 328.8558 Seconds
  User+System Time = 308.8358 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c  Name
 94.5   292.0 299.49 320314   0.0009 0.0009  Scalar::Util::refaddr
 2.00   6.188  7.447 320314   0.0000 0.0000  Scalar::Util::blessed
 0.72   2.210 139.71 166666   0.0000 0.0008  Class::Std::__ANON__
 0.48   1.488 113.10   2138   0.0007 0.0529  Class::Std::new
 0.41   1.259  1.259 320314   0.0000 0.0000
UNIVERSAL::a_sub_not_likely_to_be_
                                             here


Thanks


------------------------------

Date: Mon, 26 Nov 2007 13:41:55 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: performance problem
Message-Id: <d2ae1dda-83ea-426e-b819-2e9e5f635932@d61g2000hsa.googlegroups.com>

On Nov 26, 3:01 pm, Gizbo <anon...@gmail.com> wrote:
> Hi,
>
> My workstation was recently upgraded to Fedora 8, and this has wreaked
> havoc on the performance of my perl application.  I did a profile on
> the code and the problem appears to be within Scalar::Util.  The thing
> is, I don't know what to do next...  The code below used to take about
> 2s to run, now it is several minutes!  I use the Class::Std
> infrastructure, and that is generating the 320k calls to refaddr, but
> the same code producing the same number of calls runs in a couple
> seconds on an older workstation.
>
> Any suggestions?
>
> [ollivier@samba anc]$ dprofpp
> Total Elapsed Time = 328.8558 Seconds
>   User+System Time = 308.8358 Seconds
> Exclusive Times
> %Time ExclSec CumulS #Calls sec/call Csec/c  Name
>  94.5   292.0 299.49 320314   0.0009 0.0009  Scalar::Util::refaddr
>  2.00   6.188  7.447 320314   0.0000 0.0000  Scalar::Util::blessed
>  0.72   2.210 139.71 166666   0.0000 0.0008  Class::Std::__ANON__
>  0.48   1.488 113.10   2138   0.0007 0.0529  Class::Std::new
>  0.41   1.259  1.259 320314   0.0000 0.0000
> UNIVERSAL::a_sub_not_likely_to_be_
>                                              here
>
> Thanks

what were the old and new versions of perl?
perl --version
This is perl, v5.8.8 built for i386-linux-thread-multi

also, versions for Scalar::Util?
perl -e 'use Scalar::Util; print $Scalar::Util::VERSION;'
1.19

Why use Class::Std?  The justification is to prevent users
of your code from accessing the private fields of the classes, but
how is that your problem?  If users of a package bypass the approved
methods and a change breaks their program, well, they were warned.
I'm not a fan of forcing people to do things my way, but maybe you
have good reasons.

Also, there is a tiny chance that there could be something wrong
in your code.  I know that the possibility is vanishingly small,
but you might post a snippet showing the problem just to set our
minds at rest.
--S


------------------------------

Date: Mon, 26 Nov 2007 22:19:58 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: performance problem
Message-Id: <edtr15-is1.ln1@osiris.mauzo.dyndns.org>


Quoth Gizbo <anon24u@gmail.com>:
> 
> My workstation was recently upgraded to Fedora 8, and this has wreaked
> havoc on the performance of my perl application.  I did a profile on
> the code and the problem appears to be within Scalar::Util.

We've had reports before of Fedora 8 machines ending up with the
pure-perl version of Scalar::Util. Try running

    perl -MScalar::Util=dualvar -e1

; if it fails you need to reinstall Scalar::Util, first making sure you
have a C compiler installed.

> UNIVERSAL::a_sub_not_likely_to_be_here

Yes, this is your problem. This sub is a slightly nasty artefact of the
pure-Perl implementation.

Ben



------------------------------

Date: Mon, 26 Nov 2007 13:47:54 -0800 (PST)
From: Kevin <kbadinger@gmail.com>
Subject: Perl usage
Message-Id: <ce059f85-96c9-43f5-8553-61bfe012c424@s36g2000prg.googlegroups.com>

I was wondering if someone on this group could help out here.  I know
there are alot of positions posted on this, but was hoping someone had
some solid info to point to.

I have used Perl for projects here and there.  However my manager
keeps telling me that Perl should not be used for real projects.  It
seems like a pretty solid language to me.  Are there certain types of
applications that Perl should not be used for?  I am trying to put
together feedback from experts as to why perl is just as valid as many
other languages.  Can someone help?

http://expertcodeadvice.com/index.php?topic=7.msg14#msg14


------------------------------

Date: Mon, 26 Nov 2007 21:56:53 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Perl usage
Message-Id: <FiH2j.5885$Jy1.4154@trndny02>

Kevin wrote:
> seems like a pretty solid language to me.  Are there certain types of
> applications that Perl should not be used for?  I am trying to put

perldoc -q perl:
    "Can I do [task] in Perl?"
    "When shouldn't I program in Perl?"
    "How can I convince my sysadmin/supervisor/employees to use [...] Perl 
instead of some other language?"

jue 




------------------------------

Date: Mon, 26 Nov 2007 23:26:32 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Perl usage
Message-Id: <pan.2007.11.26.22.26.32@rtij.nl.invlalid>

On Mon, 26 Nov 2007 13:47:54 -0800, Kevin wrote:

> I was wondering if someone on this group could help out here.  I know
> there are alot of positions posted on this, but was hoping someone had
> some solid info to point to.
> 
> I have used Perl for projects here and there.  However my manager keeps
> telling me that Perl should not be used for real projects.  It seems
> like a pretty solid language to me.  Are there certain types of
> applications that Perl should not be used for?  I am trying to put
> together feedback from experts as to why perl is just as valid as many
> other languages.  Can someone help?

Your manager probably wants someone to take the blame when things go 
wrong. Saying "It's a (Microsoft|Oracle|Sun|Whatever) bug that took out a 
half year's worth of data" just is more acceptable than "It's a bug in an 
Open Source tool we use".

There is not much you can change about that. Even if it doesn't make 
sense.

Other than that, Perl is a tool, and as always use the right tool for the 
job. Sometimes that's Perl, sometimes it's not.

One good reason not to use Perl is if no one at your job can maintain 
your Perl code. Although I don't think it's a great idea to develop a MSVC
++ program that takes a week to develop and another to get the bugs out 
where a Perl one liner would have done, it is a valid viewpoint. It's the 
reason a colleague of mine develops everything in ksh, even if Perl would 
be much better suited to some tasks.

Another good reason not to use Perl is performance, although in practice 
that is seldom a real reason. I do develop programs in other languages 
when Perl is to slow. Mostly after first proving Perl is to slow, btw. 
And, as said, that's pretty seldom, Perl is pretty fast and more often 
than not fast enough.

A real good reason not to use Perl in my opinion, although many will 
disagree, is when developing big projects. By all means, use it as a glue 
language, the language for the web front-ends, for small specific 
programs within the larger project. But don't use it for projects that 
require millions of lines of code. (I won't go into what language you 
should use here, except to note that more important than the language is 
experienced seniors, good project management, a solid design that gets 
amended as the project goes along, solid regression testing and a solid 
development strategy).

But often there are many reasons why you should use Perl. Strong at text 
manipulation. Many, many good (although not always perfect) libraries. 
Strongly cross platform. Quick development. Once learned, pretty readable 
imo, but ymmv, some people think all Perl code is line noise. Good 
support for UTF-8. Comes pre-installed with many OSses. Good 
interoperation with the outside world.

Some of these reasons may apply to you, some may not. If you're in a 
Cobol shop, using Perl may make sense, but it's probably to much of a 
culture shock. If you're in a Java shop, the added cost of using an extra 
language may not be worth it. If you are in a php shop, ditto. If you are 
in a Windows only shop, installing Perl on all machines may take some 
persuasion.

Without knowing the reasons your manager has to state that he will not 
allow the use of Perl, all is just speculation, but maybe the above is of 
some help.

HTH,
M4


------------------------------

Date: 26 Nov 2007 23:00:02 GMT
From: xhoster@gmail.com
Subject: Re: Perl usage
Message-Id: <20071126180004.715$1g@newsreader.com>

Kevin <kbadinger@gmail.com> wrote:
> I was wondering if someone on this group could help out here.  I know
> there are alot of positions posted on this, but was hoping someone had
> some solid info to point to.
>
> I have used Perl for projects here and there.  However my manager
> keeps telling me that Perl should not be used for real projects.

Did your manager tell you why?  If not, then we probably can't give you
anything better than the FAQs that have already been created on this topic:

perldoc -q convince

perldoc -q shouldn

If the manager did give you reasons (not covered in the FAQs), we could
possibly formulate rebuttals to do them, if we knew what those reasons
were.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


------------------------------

Date: Mon, 26 Nov 2007 19:14:35 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: perldebtut - Perl debugging tutorial
Message-Id: <Xns99F490E30D5A9asu1cornelledu@127.0.0.1>

elsiddik <elsiddik@gmail.com> wrote in
news:15bf9029-3f09-461e-88fa-30ca323c4f91@y5g2000hsf.googlegroups.com: 

> A very lightweight introduction in the use of the perl debugger, and a
> pointer to existing, deeper sources of information on the subject of
> debugging perl programs.
> 
> There's an extraordinary number of people out there who don't appear
> to know anything about using the perl debugger, though they use the
> language every day. This is for them :
> http://sunsite.ualberta.ca/Documentation/Misc/perl-5.6.1/pod/perldebtut
> .html 

perldoc perltoc
perldoc perldebug
perldoc perldebtut

*Sigh*

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>



------------------------------

Date: Mon, 26 Nov 2007 11:47:55 -0800 (PST)
From: "alexxx.magni@gmail.com" <alexxx.magni@gmail.com>
Subject: Re: Spidering Hacks
Message-Id: <c460dc48-dc15-449a-9b36-1f4041848094@w28g2000hsf.googlegroups.com>

On 26 Nov, 20:07, Sherman Pendley <spamt...@dot-app.org> wrote:
> "alexxx.ma...@gmail.com" <alexxx.ma...@gmail.com> writes:
> > Probably then it's my mistake.
>
> Don't lose sleep over it - it wasn't a very big one. :-)
>
> > I often asked for help/advice in this group, since I use Perl heavily,
> > and it seldom let me down - I used to feel rather at home here.
>
> Please feel free to continue feeling that way! Granted, my first "did you
> have a Perl question" was kind of snarky, and I apologize for that. But I
> honestly intended to be helpful - it's my opinion that choosing the right
> group for a question is as critical a research skill as choosing the right
> keywords for a Google search.
>

Well, thank you for the kind words, I feel better!

Alessandro

P.S. still unsure, however, which would have been the right
group??? ;-)


------------------------------

Date: Mon, 26 Nov 2007 16:26:16 -0500
From: Sherman Pendley <spamtrap@dot-app.org>
Subject: Re: Spidering Hacks
Message-Id: <m1fxysitqf.fsf@dot-app.org>

"alexxx.magni@gmail.com" <alexxx.magni@gmail.com> writes:

> P.S. still unsure, however, which would have been the right
> group??? ;-)

If you go to the list of Google APIs here:

    <http://code.google.com/more/>

When you click the name of the API on the list to the left, a list of
resources related to that API appears on the right. It looks to me like
most of them have groups; I don't know if those groups are GG-only, or
if the major usenet providers are also carrying them.

sherm--

-- 
WV News, Blogging, and Discussion: http://wv-www.com
Cocoa programming in Perl: http://camelbones.sourceforge.net


------------------------------

Date: Mon, 26 Nov 2007 19:36:54 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: ST
Message-Id: <qfF2j.14322$Mg1.7210@trndny03>

nolo contendere wrote:
> On Nov 26, 11:42 am, "Jürgen Exner" <jurge...@hotmail.com> 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 




------------------------------

Date: Mon, 26 Nov 2007 11:37:07 -0800 (PST)
From: Paul Lalli <mritty@gmail.com>
Subject: Re: ST
Message-Id: <d280b887-7450-4b5a-964f-314120cccf3a@t47g2000hsc.googlegroups.com>

On Nov 26, 11:28 am, tekwiz <ryo...@medicalpharmacies.com> 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


------------------------------

Date: Mon, 26 Nov 2007 11:45:43 -0800 (PST)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: ST
Message-Id: <34cd2ee2-b759-4e12-a1a9-35ce9e11d779@s8g2000prg.googlegroups.com>

On Nov 26, 2:37 pm, Paul Lalli <mri...@gmail.com> wrote:
> On Nov 26, 11:28 am, tekwiz <ryo...@medicalpharmacies.com> 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...


------------------------------

Date: Mon, 26 Nov 2007 12:01:07 -0800 (PST)
From: tekwiz <ryoung@medicalpharmacies.com>
Subject: Re: ST
Message-Id: <ca56491c-f142-436d-aa30-a1e24c116d2d@s12g2000prg.googlegroups.com>

On Nov 26, 2:45 pm, nolo contendere <simon.c...@fmr.com> wrote:
> On Nov 26, 2:37 pm, Paul Lalli <mri...@gmail.com> wrote:
>
>
>
> > On Nov 26, 11:28 am, tekwiz <ryo...@medicalpharmacies.com> 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.


------------------------------

Date: Mon, 26 Nov 2007 14:11:37 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: ST
Message-Id: <261120071411371006%jimsgibson@gmail.com>

In article
<ca56491c-f142-436d-aa30-a1e24c116d2d@s12g2000prg.googlegroups.com>,
tekwiz <ryoung@medicalpharmacies.com> 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


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 1066
***************************************


home help back first fref pref prev next nref lref last post