[13550] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 960 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 1 01:07:10 1999

Date: Thu, 30 Sep 1999 22:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <938754308-v9-i960@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 30 Sep 1999     Volume: 9 Number: 960

Today's topics:
    Re: Catching errors in anouther name space. <admin@gatewaysolutions.net>
    Re: Catching errors in anouther name space. <rootbeer@redcat.com>
    Re: Catching errors in anouther name space. <admin@gatewaysolutions.net>
    Re: How to list values of all variables during program  <rootbeer@redcat.com>
        loop in perl <r42317@email.sps.mot.com>
    Re: loop in perl <rootbeer@redcat.com>
    Re: No -e allowed in setuid scripts <rootbeer@redcat.com>
        perl & javascript!? <rc3csb@usa.net>
    Re: ping script to page mobile... <rootbeer@redcat.com>
    Re: piping a variable to an external command <rootbeer@redcat.com>
    Re: Q: Syntax to open a file in PERL on an NT server <gremlin@ix.netcom.com>
        remove spaces <hpya78@postoffice.pacbell.net>
    Re: remove the html tag in the file <kbandes@home.com>
    Re: Server emulation offline <jeff@vpservices.com>
    Re: setpwent (Martien Verbruggen)
    Re: setpwent <uri@sysarch.com>
    Re: Sorting weird numeric data <uri@sysarch.com>
    Re: Sorting weird numeric data (Bill Moseley)
        Trouble with or... (J. Moreno)
    Re: Trouble with or... <uri@sysarch.com>
    Re: Trouble with or... <rootbeer@redcat.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 30 Sep 1999 22:13:54 -0500
From: "Scott Beck" <admin@gatewaysolutions.net>
Subject: Re: Catching errors in anouther name space.
Message-Id: <rv89i4kg3i594@corp.supernews.com>

David Cassell <cassell@mail.cor.epa.gov> wrote in message
news:37F40286.E4A68276@mail.cor.epa.gov...
> Scott Beck wrote:
> [snip of TomP's post]
> > The only output from this is
> > Script add.cgi
> > running on Thu Sep 30 17:10:12 1999 (Perl version 5.00404)
> >
> > This is probably because the script is dying in another name space, well
at
> > least that is my opinion but I am not sure since I have no error message
to
> > work with.
>
> Then you missed Tom's point.  If you use his BEGIN block and
> then scatter the usual
>     yadda(yadda,yadda) or die "Blech: $!";

And I did.

> kind of Perl code through your script, then you'll get error
> checking which shows up on your webpage for easy viewing and
> debugging.

And I didn't

If you look a the previous instances of this thread you will find that I do
have the usual
yadda(yadda,yadda) or die "Blech: $!";
throughout the code.

Thanks
Scott



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

Date: Thu, 30 Sep 1999 20:59:35 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Catching errors in anouther name space.
Message-Id: <Pine.GSO.4.10.9909302057430.17231-100000@user2.teleport.com>

On Thu, 30 Sep 1999, Scott Beck wrote:

> > Then you missed Tom's point.  If you use his BEGIN block and
> > then scatter the usual
> >     yadda(yadda,yadda) or die "Blech: $!";
> 
> And I did.
> 
> > kind of Perl code through your script, then you'll get error
> > checking which shows up on your webpage for easy viewing and
> > debugging.
> 
> And I didn't

So, are you saying that somehow your program is giving up the ghost
without a whimper? It sounds as if some evil programmer has slipped an
"exit" where you weren't expecting one. At least, that's my best guess at
the moment.

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 30 Sep 1999 23:50:40 -0500
From: "Scott Beck" <admin@gatewaysolutions.net>
Subject: Re: Catching errors in anouther name space.
Message-Id: <rv8fcpk63i550@corp.supernews.com>

>
> So, are you saying that somehow your program is giving up the ghost
> without a whimper?

It is not giving any errors. It is just stopping dead.

 >It sounds as if some evil programmer has slipped an
> "exit" where you weren't expecting one. At least, that's my best guess at
> the moment.
>

Yea I know it sounds silly and I never expected it.
This program runs fine on my Linux box therefore I suspect it is
one of the modules that I am calling or perhaps the connection to the
Database
but I thought I was doing all there error checking that was possible.
Did you look at the code Tom?



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

Date: Thu, 30 Sep 1999 20:55:50 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: How to list values of all variables during program execution?
Message-Id: <Pine.GSO.4.10.9909302055240.17231-100000@user2.teleport.com>

On 1 Oct 1999, TGarner5 wrote:

> How do you "suspend" a script and see the value of all memory
> variables or a specific variable during script execution?

I use the perl debugger. Have you read the perldebug manpage? Hope this
helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 01 Oct 1999 11:48:55 +0800
From: Noira Hadi <r42317@email.sps.mot.com>
Subject: loop in perl
Message-Id: <37F42F26.25922A33@email.sps.mot.com>

This is a multi-part message in MIME format.
--------------30C8A46A5E79DE308998FC01
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hello,

I just learn Perl self-paced for two weeks and currently I work to
reformat a group of data to standardize them.

I have problem with looping. I have long list of data which has pattern
as in the script below. I re-format them from the list and combine to a
single line for each group of data where each lines are identified by
MIR, SBR, HBR, SDR, MRR ( For clarity of original data group, pls refer
to the end part of this mail). However, I got stuck with SBR & HBR where
the condition is slightly different.

These two type of data has varying number of lines(let say maximum of 16
lines from original data), but I need to make them standardized such
that I will put '0'( zero values ) for substitution to the fields
whenever they are less than 16 lines.

I tried looping the SBR lines 16 times but then all the lines with SBR
was multiplied 16 times from the original.

I want to know if there is a way that I can turn off the outside loop
where I can force the script to execute 16 times after reading the first
line of SBR and read them. If the lines of SBR is less than 16 then I
will put zeroes to the fields to substitute the original.



Here is the script:

#!/usr/local/bin/perl -w
          open(INF,"data") ;
          @ary = <INF>;
          close(INF);

for ($ary=1; $ary<2; $ary++) {
          foreach $line (@ary) {
            if ($line =~ /MIR/){
              chomp($line);
              print "$line,";
            }
            elsif ($line =~ /SBR/) {
              $num=0;
              $num=$num+1;
              chomp($line);
              print "$line, $num,";
#             print "hadi,";
            }
            elsif ($line =~ /HBR/) {
              chomp($line);
              print "$line,";
            }
            elsif ($line =~ /SDR/) {
              chomp($line);
              print "$line,";
            }
            elsif ($line =~ /MRR/){
                 print "$line\r";
            }
            else {
                end     ;
            }
        }
}

For clarity, you may run the following text data with the above script:-

MIR1,98/11/26 13:08:47,,HW66952102,4X2,SYS33 ,3326,HC05B6  ,114
MIR2,25468A,95,B16,D60J,STF,ZC505926CFNR2,2099
SBR1,1,1,286,12,24,0,1,0,0,0,0,0,0,0,1,0,0,1
SBR2,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,13,0
SBR1,1,2,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0
SBR2,1,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
SBR1,1,3,264,2,56,0,1,0,1,0,0,0,0,0,0,0,0,0
SBR2,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11,0
SBR1,1,4,230,6,20,0,0,0,1,1,0,18,0,0,0,0,0,1
SBR2,1,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0
SBR1,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
SBR2,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
SBR1,2,2,372,8,34,0,0,0,0,0,0,0,0,0,0,0,0,1
SBR2,2,2,0,1,0,0,0,0,0,0,0,0,0,0,0,0,7,0
SBR1,2,3,371,8,36,0,0,0,0,0,0,0,0,0,1,0,0,1
SBR2,2,3,0,0,0,0,0,0,0,1,0,0,0,0,0,0,6,0
SBR1,2,4,357,10,54,0,1,0,0,0,0,0,0,0,0,0,0,0
SBR2,2,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0
HBR,1,1,286,1,13,0,3,0,0,36
HBR,1,2,0,0,0,0,2,0,0,0
HBR,1,3,264,0,11,1,1,0,0,58
HBR,1,4,230,0,8,20,1,0,0,26
SDR,1,NONE-000,BXQ-0000
HBR,2,1,0,0,0,0,0,0,0,0
HBR,2,2,372,0,7,1,1,0,0,42
HBR,2,3,371,0,6,1,2,0,0,44
HBR,2,4,357,0,4,0,1,0,0,64
SDR,2,NONE-000,BXQ-0000
MRR,98/11/26 16:44:09,2234
MIR1,98/11/21 06:38:36,T,TESTER-CHECK,1X1,SYS33 ,3326,SCHECK  ,101
MIR2,TECH,25,TSG,TSG,NPT,STRBCHCK,0000
SBR1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
SBR2,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
HBR,1,1,0,0,0,0,0,0,0,0
SDR,1,ASEC-000,NPM-0000
MRR,98/11/21 06:39:31,1

Thanks & Regards,
hadi omar

--------------30C8A46A5E79DE308998FC01
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Hadi Noira Omar
Content-Disposition: attachment; filename="vcard.vcf"

begin:          vcard
fn:             Hadi Noira Omar
n:              Omar;Hadi Noira
org:            <a href=http://www.mcu.motsps.com><img src=http://apgweb.sps.mot.com/apspg/digitaldna/quiz/images/ad.gif border=0></a>
adr:            Computer Integrated Manufacturing (CIM), ;;Research & Development ;No.2, Jalan SS 8/2, ;Free Industrial Zone Sg.Way, ;47300 Petaling Jaya,;MALAYSIA
email;internet: r42317@email.sps.mot.com
title:          System Engineer, Motorola (Malaysia) Sdn Bhd
tel;work:       03 773-4441
tel;fax:        03 773-1398
x-mozilla-cpt:  ;-25616
x-mozilla-html: FALSE
version:        2.1
end:            vcard


--------------30C8A46A5E79DE308998FC01--



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

Date: Thu, 30 Sep 1999 21:44:57 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: loop in perl
Message-Id: <Pine.GSO.4.10.9909302138210.17231-100000@user2.teleport.com>

On Fri, 1 Oct 1999, Noira Hadi wrote:

[ Description of situation snipped. ]

I don't completely understand what you're trying to do. If you are more
fluent in another language than English, you may wish to use that language
to ask your question again.

> I want to know if there is a way that I can turn off the outside loop
> where I can force the script to execute 16 times after reading the
> first line of SBR and read them.

You may want to use 'last' with a label. See the perlfunc manpage.

>           open(INF,"data") ;

Even when your script is "just an example" (and perhaps especially in that
case!) you should _always_ check the return value after opening a file.

> for ($ary=1; $ary<2; $ary++) {

This looks like a lot of trouble to go to in order to loop just once. Is
that doing what you want?

>           foreach $line (@ary) {

You know that this variable @ary has nothing to do with the $ary from
before. Right?

>               $num=0;
>               $num=$num+1;

That's a difficult way to store 1 into $num. I don't think that's what you
want, but I don't know what to suggest instead.

>             elsif ($line =~ /HBR/) {
>               chomp($line);
>               print "$line,";
>             }
>             elsif ($line =~ /SDR/) {
>               chomp($line);
>               print "$line,";
>             }

Maybe you want to use 'or'. Maybe you want to chomp $line when you first
read it, rather than conditionally. 

>             elsif ($line =~ /MRR/){
>                  print "$line\r";

Are you sure you want \r and not \n there?

>                 end     ;

Is that doing what you want?

It may be that you should cut your program down to a small, stand-alone
example which shows more clearly just which behavior is puzzling to you,
then you could post that.

Good luck!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 30 Sep 1999 20:33:25 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: No -e allowed in setuid scripts
Message-Id: <Pine.GSO.4.10.9909302014400.17231-100000@user2.teleport.com>

On Thu, 30 Sep 1999 musta@efn.org wrote:

> % ./usergroup
> No -e allowed in setuid scripts.

Looks like a bug. Try running it as a true set-id script (instead of
compiling it) and see what happens. 

Of course, if that works, you'll have to ask yourself what you're gaining
by compiling. :-)

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 1 Oct 1999 12:14:21 +0800
From: "csb" <rc3csb@usa.net>
Subject: perl & javascript!?
Message-Id: <37f43599.0@news.highway1.com.au>

hi,
    i created an array in perl, say @num which has values (1,2,3,4,5)..the
problem occur when i use the @num in javascript...the following is the
program:
==============================
#!/usr/local/bin/perl -w
 ....
 ..........
 .....
   @num = (1,2,3,4,5);

   &generateHTML;

#===========================================================================
=================
sub generateHTML
{

print <<HTML;

<SCRIPT LANGUAGE="JavaScript1.2">

  var jArray = new Array(@num)   <-------------- can i do something like
that?..coz i have error in here.
   ............

</script

 .......
 ......
 ......

HMTL;










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

Date: Thu, 30 Sep 1999 20:53:02 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: ping script to page mobile...
Message-Id: <Pine.GSO.4.10.9909302052410.17231-100000@user2.teleport.com>

On Fri, 1 Oct 1999, jakal wrote:

> Has anyone written a Perl script that will ping a server, any page a
> mobile if the server is down?

Probably.

If you're wishing merely to _find_ (as opposed to write) programs,
this newsgroup may not be the best resource for you. There are many
freeware and shareware archives which you can find by searching Yahoo
or a similar service. Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 30 Sep 1999 20:51:38 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: piping a variable to an external command
Message-Id: <Pine.GSO.4.10.9909302049540.17231-100000@user2.teleport.com>

On Thu, 30 Sep 1999, Clifford Meece wrote:

> I have tried opening the program like
> open(PROGRAM, "|progam")
> and then just printing to that file handle, but it doesn't seem to work.

You seem to be on the right track, but maybe you spelled the program name
wrong. If that's not it, maybe you need to show us your actual code,
rather than something like it. Of course, you should first cut it down to
the smallest stand alone example. Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 01 Oct 1999 00:39:53 -0400
From: gremlin <gremlin@ix.netcom.com>
Subject: Re: Q: Syntax to open a file in PERL on an NT server
Message-Id: <37F43B19.6489EAA8@ix.netcom.com>

With regard to "relative paths".  If an NT "Share" was made, would THAT
be relative (as I read 'D:\yaddah\yaddah\yaddah...' was)?



Necromancer wrote:
> 
> On Thu, 30 Sep 1999 14:21:23 GMT, necr0mancer@myremarq.com
> (Necromancer) wrote:
> 
> >I've been a PERL scripter on UNIX for quite awhile, but I've never had
> >to create PERL for NT.  The scripts I had I'm having to port over, and
> >I can't even get data files to read in!  Can someone help?
> >
> >My old syntax was:
> >
> >open(DATA,"<../data/newratesdata.txt");


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

Date: Thu, 30 Sep 1999 21:30:11 -0700
From: Linda White <hpya78@postoffice.pacbell.net>
Subject: remove spaces
Message-Id: <37F438D3.56B79E52@postoffice.pacbell.net>

Hello,
I  have a file like:.
 $ans = "            1234\n";
 @aaa = $ans =~ /^\s//;
 print "@aaa\n";

Can someone help me remove spaces and get 1234 ONLY.
      Thank






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

Date: Fri, 01 Oct 1999 03:18:39 GMT
From: Kenneth Bandes <kbandes@home.com>
Subject: Re: remove the html tag in the file
Message-Id: <37F4281E.FB54FA8B@home.com>

Abigail wrote:
> Samuel Kilchenmann (skilchen@swissonline.ch) wrote on MMCCXIX September
> MCMXCIII in <URL:news:lK%H3.19563$m4.77238483@news.magma.ca>:
[elided stuff]
> -- So what Perl has to offer:
> -- TOMC's striphtml (which may be good enough for most purposes, but which
> -- does not handle nested comments (are they illegal?))
[and so forth]
>
> Perl also has to offer:
> 
>      open (NSGMLS, "| /usr/local/bin/nsgmls")

which is actually the right answer to the original question.  nsgmls
is James Clark's SGML (and therefore HTML and XML) parser.  Pretty
much the entire SGML industry depends on Clark's open source parsers.
nsgmls (and sgmls, its predecessor) emits a representation called
ESIS (Element Structure Information Set) which is very easy to
process with Perl.  The following more or less does the job, i.e.
prints the text contents of all elements:

use strict;

my $file = shift or die "Usage: $0 filename\n";

open(SGML, "nsgmls $file |") or die "Unable to run nsgmls: $!";

while(<SGML>)
{
    if(/^-/) # text contents of an element
    {
        my $text = substr $_, 1;
        $text =~ s/\\n/\n/g;
        print $text;
    }
}
close(SGML);

I say "more or less" because other escape sequences could occur
that I haven't bothered with here.  Needs a few more lines.

nsgmls is available at http://jclark.com/sp.  A good book about
this stuff (including a few Perl samples) is "PARSEME.1ST:
SGML for Software Developers" by Sean McGrath.

Ken Bandes


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

Date: 1 Oct 1999 02:49:37 GMT
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Server emulation offline
Message-Id: <37F41F76.25FD1D1B@vpservices.com>

Matt & Michelle wrote:
> 
> I would like to beable to run my cgi/perl programs offline when working on
> my webpage. I  need to know what to install to get my computer to run my
> offline webpage as if it were running off a server. 

You need a web server.  Apache and many other web servers are freely
downloadable and easy to install and can be run offline as easily as
online.  You don't tell us what platform you are running on, but on the
wild guess that you are a Prisoner of Bill (i.e. you are on some version
of windoze), apache, xitami, omnihttpd, and others are all available at
websites closely resembling their names.

> I have installed Standard Perl 5.004.

That is an old version.  The current stable version is 5.005.03.  Might
as well start out with the right version.  If you are on windoze, get it
from www.activeState.com.

Since you are interested in cgi, your best bet is to look up CGI.pm as
soon as you have the rest of the stuff installed.

If you have trouble installing the webserver or configuring it to run
Perl, try on one of the server newsgroups or a newsgroup devoted to your
OS.  If you have trouble making the cgi work, try the faqs or newsgroups
related to cgi.  If you are having problems with Perl syntax, then this
is the place to come.

-- 
Jeff


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

Date: Fri, 01 Oct 1999 03:25:15 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: setpwent
Message-Id: <vQVI3.130$Fy1.5807@nsw.nnrp.telstra.net>

On Thu, 30 Sep 1999 22:56:14 -0300,
	R. Brockway <rockie@apk.net> wrote:

> which then tells me i'm going about this all wrong, as setpwent will only
> set or reset the emuneration relative to the password file (position), not
> actually have the ability to set fields in the passwd entry. usermod
> (solaris) does not have an option (at least documented) to modify the gecos
> string and we have seen that sudo passwd -g rarely, but occasionally does
> not free up the passwd file. looking for another way to change gecos
> fields.

I think the -c option to usermod changes the gcos field, they
just call it 'comment' for whatever silly reason. Note that passwd -g
is Solaris specific. It's -f on many other systems, and chfn on others
still.

I have never seen passwd -g not free up the passwd file (meaning that
the lock stays around or something?), but I have seen some odd
behaviour under sudo on Solaris, although I can't remember exactly
anymore what it was doing.

Setting fields in passwd strings is a very system and configuration
dependent thing (yp, NIS, shadow), and therefore hard to express in a
general API. AFAIK you will need to use OS specific tools.

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | Failure is not an option. It comes
Commercial Dynamics Pty. Ltd.       | bundled with your Microsoft product.
NSW, Australia                      | 


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

Date: 01 Oct 1999 00:31:35 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: setpwent
Message-Id: <x7905nvh08.fsf@home.sysarch.com>

>>>>> "MV" == Martien Verbruggen <mgjv@comdyn.com.au> writes:

  MV> I think the -c option to usermod changes the gcos field, they
  MV> just call it 'comment' for whatever silly reason. Note that passwd -g
  MV> is Solaris specific. It's -f on many other systems, and chfn on others
  MV> still.

just to back you up, here is -c from solaris usermod:

	-c comment
		Specify a comment string. comment can be any  text
		string. It is generally a short description of the
		login, and is currently used as the field for  the
		user's  full  name.  This information is stored in
		the user's  /etc/passwd entry.

it doesn't mention the field of /etc/passed or pwent but anyone with
some brains will associate the gcos field with a user name or a comment
since that is all it is used for these days.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: 01 Oct 1999 00:17:46 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Sorting weird numeric data
Message-Id: <x7btajvhn9.fsf@home.sysarch.com>

>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:

  LR> In article <37F40D42.94380277@rochester.rr.com> on Thu, 30 Sep 1999 
  LR> 21:24:18 -0400, Bob Walton <bwalton@rochester.rr.com> says...
  LR> ...

  >> ...  If one can obtain a sort of O(N) by making some assumptions 
  >> that are actually present anyway, why the resistance to the idea?
  >> And note that the data for most any sort comparison can be
  >> pack'ed into strings for comparison purposes (there was even a
  >> discussion of how to do that for floating point data in this
  >> thread).  Therefore, most any sort could be performed O(N).

  LR> Who is resistant to the idea?   All you have to do is to post a 
  LR> demonstration of your method, with benchmarks that show O(N) behavior 
  LR> over several decades of N.  Your data can consist of lists of arbitrary 
  LR> strings of reasonable length, say a few dozen characters each.

the problem is the old apples and oranges thing. when discussing O() you
have to define what is the operation you are counting. in sorting
integers it is <=>, in sorting strings it is cmp. it is not $char1 eq
$char2. the string compare is considered the bottleneck operation and it
is what grows with the size of the dataset. the char compares do not
grow any more with the data set size so they are considered a constant
factor of the cmp operation. this is why sorts which disk thrash blow up
beyond N Log N since the disk accesses overwhelms the cmp operations. so
then you do a disk/tape sort algorithm and consider sorting an in-memory
dataset as ONE operation and you count those in an O() function.

so for general sort problems you can't get faster than N log N. for
special cases where you have known restrictions on the data you can do
better such as with a radix sort on integers. but that is a special case
and comparing 1.2.3 type values is not that kind of case. it basically
is a string compare. counting char compares in that sort is misleading
and an inaccurate analysis of the algorithm. you count the string
compares or the number of time sort calls the sort sub. that is the
driving bottleneck that grows N log N with dataset size.

god, i can't believe i remember this stuff after so many years.

uri


-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Thu, 30 Sep 1999 21:49:14 -0700
From: moseley@best.com (Bill Moseley)
Subject: Re: Sorting weird numeric data
Message-Id: <MPG.125ddd21794363319897a7@206.184.139.132>

Uri Guttman (uri@sysarch.com) seems to say...
> >>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
 ...about sorting.

Here's a design question:

Often it's mentioned that the sorting method depends on the size of the 
data set.  Larry commented today about using the sort utility instead of 
Perl's built-in for a large sort.

As just a worker-bee programmer, how do I decided during the code design 
phase when some sort is so large I need to consider another method -- 
especially when the program is, say, a CGI script that I'm not 
monitoring every time it runs?

I mean, should a light go off in my head at some threshold? -- "Say, I'm 
sorting 10,000 records now, but in a year it may be 50,000 records and 
that seems like a lot! I better farm this out to the sort utility."

Or should I, as I remarked in another thread, just wait for the sysadmin 
to come calling?

-- 
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.


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

Date: Thu, 30 Sep 1999 23:58:10 -0400
From: planb@newsreaders.com (J. Moreno)
Subject: Trouble with or...
Message-Id: <1dyyy0n.f2iurrsf05nhN@roxboro0-0006.dyn.interpath.net>

Anybody got any idea as to why this script would fail to compile?  What
am I missing?

#!/usr/bin/perl -w

open(EXAMPLE, '<datafile') or print 'this';

syntax error in file test.cgi at line 3, next 2 tokens ") or"
Execution of test.cgi aborted due to compilation errors.


if I comment out the or, it works, but otherwise...

-- 
John Moreno


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

Date: 01 Oct 1999 00:37:32 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Trouble with or...
Message-Id: <x7670rvgqb.fsf@home.sysarch.com>

>>>>> "JM" == J Moreno <planb@newsreaders.com> writes:

  JM> open(EXAMPLE, '<datafile') or print 'this';

  JM> syntax error in file test.cgi at line 3, next 2 tokens ") or"
  JM> Execution of test.cgi aborted due to compilation errors.

  JM> if I comment out the or, it works, but otherwise...

paging dr. howard, dr fine, dr. howard!

hugo z. hackenbush at your service!

i smell a camel carcass! who you calling a dead camel? you of course!
now go and bury it and get yourself a fresh camel from cpan.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Thu, 30 Sep 1999 21:50:35 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Trouble with or...
Message-Id: <Pine.GSO.4.10.9909302145570.17231-100000@user2.teleport.com>

On Thu, 30 Sep 1999, J. Moreno wrote:

> Anybody got any idea as to why this script would fail to compile?  
> What am I missing?

A recent version of Perl. You're using Perl 4, which is dead, dead, dead.
You should (tell your system administrator to) install a version of Perl
significantly newer than the one which has had outstanding CERT security
warnings against its use since the long-ago days when Monica was still an
intern.

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 960
*************************************


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