[17211] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4633 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 16 18:10:58 2000

Date: Mon, 16 Oct 2000 15:10:25 -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: <971734225-v9-i4633@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 16 Oct 2000     Volume: 9 Number: 4633

Today's topics:
    Re: question <joe+usenet@sunstarsys.com>
    Re: question <anmcguire@ce.mediaone.net>
    Re: question <joe+usenet@sunstarsys.com>
    Re: question <anmcguire@ce.mediaone.net>
    Re: question <jboes@eomonitor.com>
    Re: question <joe+usenet@sunstarsys.com>
    Re: question <ren.maddox@tivoli.com>
    Re: Regex for matching e-mail addresses <jboes@eomonitor.com>
    Re: Save As... Popup box <jeff@vpservices.com>
    Re: Save As... Popup box <mjcarman@home.com>
        Saving Textarea to text file <19wlr@globalnet.co.uk>
        Sorting a list <sylvain2k@sympatico.ca>
    Re: Sorting a list <kistler@gmx.net>
    Re: Sorting a list (Randal L. Schwartz)
    Re: Sorting a list (Colin Watson)
    Re: Sorting a list <uri@sysarch.com>
    Re: Sorting a list (Randal L. Schwartz)
    Re: Sorting is too slow for finding top N keys... - UPD (Michel Dalle)
        Spawning Perl Processes From Perl hankahn2@my-deja.com
    Re: Spawning Perl Processes From Perl (Andrew J. Perrin)
    Re: split problem <godzilla@stomp.stomp.tokyo>
    Re: split problem <mjcarman@home.com>
        Starting Background Processes With PERL hankahn2@my-deja.com
        Substracting one list from another <nospam@luisr@juanadiaz.org>
    Re: Substracting one list from another <Darryl.Friesen@usask.ca>
        Telling difference between a package and a class? trollis@my-deja.com
        Threads and SMP <louis@trapezoid.com>
        Tracking user in perl CGI... HELP! lorddcee@my-deja.com
    Re: Tracking user in perl CGI... HELP! <prlawrence@lehigh.edu>
    Re: What is wrong with this subroutine? <walt@myxa.com>
    Re: What is wrong with this subroutine? <james@NOSPAM.demon.co.uk>
    Re: XBase module <don@lclcan.com>
    Re: XBase module <jeff@vpservices.com>
    Re: XSL (from CGI) not kept on server? <jim@usjet.net>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 16 Oct 2000 14:23:00 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: question
Message-Id: <m3zok4prwb.fsf@mumonkan.sunstarsys.com>

Apology accepted, and returned in kind :)
Let me include the original code of Martien
and I so we discuss it.

"Andrew N. McGuire " <anmcguire@ce.mediaone.net> writes:

> JS> Here's Martien's action:

sub action
{
    local($., *IN);
    open(IN, $fileB) or die $!;
    1 while (my $line = <IN>);
    return $.;
}


> JS> Here's the original:

sub action {

  my $line = pop;
  open (FILEB, "<$fileB");

  while (<FILEB>) {
    #do something interesting with $line
  }

  close FILEB ;
  return $line;

}

> So a natural combination of the two yields:
> 
> # $fileB renamed to $file_b
> 
> sub action ($) {
>     local($., *IN);
>     my $line = shift;
>     open IN, $file_b or die $!;
>     1 while <IN>;
>     return $line;
> }

Well done!  However, I think you've forgotten
an essential piece of the original inplementation
of action.  In the original "action", each time
it's called, the entirety of fileB is parsed.
In Martien's solution, and yours as well, fileB
is only read the first time that action is called.
in particular, your code's

1 while <IN>;

line will only be looped through on the first call
of your "action".  Subsequent calls will bypass this
line, since you've already read the entire file in,
but you didn't *close* it in your code.

This certainly gets $. "right", but for the wrong 
reason.  I'm still looking for a better solution,
but I think we're finally getting somewhere on this
thread.

Good luck!
-- 
Joe Schaefer



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

Date: Mon, 16 Oct 2000 14:14:22 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: question
Message-Id: <Pine.LNX.4.21.0010161408100.25153-100000@hawk.ce.mediaone.net>

On 16 Oct 2000, Joe Schaefer quoth:

JS> Apology accepted, and returned in kind :)
JS> Let me include the original code of Martien
JS> and I so we discuss it.
JS> 
JS> "Andrew N. McGuire " <anmcguire@ce.mediaone.net> writes:
JS> 
JS> > JS> Here's Martien's action:
JS> 
JS> sub action
JS> {
JS>     local($., *IN);
JS>     open(IN, $fileB) or die $!;
JS>     1 while (my $line = <IN>);
JS>     return $.;
JS> }
JS> 
JS> 
JS> > JS> Here's the original:
JS> 
JS> sub action {
JS> 
JS>   my $line = pop;
JS>   open (FILEB, "<$fileB");
JS> 
JS>   while (<FILEB>) {
JS>     #do something interesting with $line
JS>   }
JS> 
JS>   close FILEB ;
JS>   return $line;
JS> 
JS> }
JS> 
JS> > So a natural combination of the two yields:
JS> > 
JS> > # $fileB renamed to $file_b
JS> > 
JS> > sub action ($) {
JS> >     local($., *IN);
JS> >     my $line = shift;
JS> >     open IN, $file_b or die $!;
JS> >     1 while <IN>;
JS> >     return $line;
JS> > }
JS> 
JS> Well done!  However, I think you've forgotten
JS> an essential piece of the original inplementation
JS> of action.  In the original "action", each time
JS> it's called, the entirety of fileB is parsed.
JS> In Martien's solution, and yours as well, fileB
JS> is only read the first time that action is called.
JS> in particular, your code's
JS> 
JS> 1 while <IN>;
JS> 
JS> line will only be looped through on the first call
JS> of your "action".  Subsequent calls will bypass this
JS> line, since you've already read the entire file in,
JS> but you didn't *close* it in your code.

That is not true though. :-)  for every subsequent open() after
the first, close() is called implicitly.  This is documented in
them close() manpage ('perldoc -f close').  The difference is
that an explicit close resets $., while an implicit one does
not.  In this case it does not matter though, as you have
localized its scope anyhow, but the choice is still there. :-)

JS> This certainly gets $. "right", but for the wrong 
JS> reason.  I'm still looking for a better solution,
JS> but I think we're finally getting somewhere on this
JS> thread.

If you still think that $. looks obfuscated, you can always:

use English;

then you can call it $NR (as in awk) or $INPUT_LINE_NUMBER.

anm
-- 
$ # = "%.6g" ; stat $0 or die $! ;
_ = q.Just another Perl Hacker.  ;
print $ #                        ;
main'_ . v10                     ;



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

Date: 16 Oct 2000 15:19:20 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: question
Message-Id: <m3snpwppaf.fsf@mumonkan.sunstarsys.com>

Joe Schaefer <joe+usenet@sunstarsys.com> writes:

> In Martien's solution, and yours as well, fileB
> is only read the first time that action is called.
> in particular, your code's
> 
> 1 while <IN>;
> 
> line will only be looped through on the first call
> of your "action".  Subsequent calls will bypass this
> line, since you've already read the entire file in,
> but you didn't *close* it in your code.
> 
> This certainly gets $. "right", 

I spoke too soon-  

1 while <IN>; 

is reevaluated each time action is called- my mistake!
( I think "}" is closing the file for you.)
Your code still doesn't seem to work, though- if I use
this:
-----
my $file_b = "/tmp/fileB";

sub action ($) {
    local($., *IN);
    my $line = shift;
    open IN, $file_b or die $!;
    print while <IN>;
    return $line;
}
------

here's my output:

% ./try.pl

A is at line:1
HI
THERE
It reads: ALPHA
A still is at line:0
HUH?

A is at line:2
HI
THERE
It reads: BETA
A still is at line:0
HUH?

A is at line:3
HI
THERE
It reads: GAMMA
A still is at line:0
HUH?

A is at line:4
HI
THERE
It reads: DELTA
A still is at line:0
HUH?



% cat /tmp/fileA
ALPHA
BETA
GAMMA
DELTA

% cat /tmp/fileB
HI
THERE

It still seems that we're missing something :)

-- 
Joe Schaefer


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

Date: Mon, 16 Oct 2000 15:08:42 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: question
Message-Id: <Pine.LNX.4.21.0010161503200.25157-100000@hawk.ce.mediaone.net>

On 16 Oct 2000, Joe Schaefer quoth:

JS> Joe Schaefer <joe+usenet@sunstarsys.com> writes:
JS> 
JS> > In Martien's solution, and yours as well, fileB
JS> > is only read the first time that action is called.
JS> > in particular, your code's
JS> > 
JS> > 1 while <IN>;
JS> > 
JS> > line will only be looped through on the first call
JS> > of your "action".  Subsequent calls will bypass this
JS> > line, since you've already read the entire file in,
JS> > but you didn't *close* it in your code.
JS> > 
JS> > This certainly gets $. "right", 
JS> 
JS> I spoke too soon-  
JS> 
JS> 1 while <IN>; 
JS> 
JS> is reevaluated each time action is called- my mistake!
JS> ( I think "}" is closing the file for you.)
JS> Your code still doesn't seem to work, though- if I use
JS> this:

Actually it is open() that closes the file file by implicitly calling
close() for every open() after the first. ( Thats a mouthful ).

[ snip somehow broken test ]

It works for me. :-)

[anm@eagle ~] cat file_a                                                [pts/2]
ALPHA
BETA
GAMMA
DELTA
[anm@eagle ~] cat file_b                                                [pts/2]
HI
THERE
[anm@eagle ~] cat test.pl                                               [pts/2]
#!/usr/bin/perl -w
use strict;

package Distant;

my $file_b = 'file_b';

sub action ($) {
    local($., *IN);
    my $line = shift;
    open IN, $file_b or die $!;
    print while <IN>;
    return $line;
}

1;

package main;

my $file_a = 'file_a';
open IN, $file_a or die $!;

while ( <IN> ) {
    print "A is at line: $.\n";
    print "It reads: ", Distant::action($_); 
    print "A is still at line $.\n";
}

close IN;
[anm@eagle ~] ./test.pl                                                 [pts/2]
A is at line: 1
HI
THERE
It reads: ALPHA
A is still at line 1
A is at line: 2
HI
THERE
It reads: BETA
A is still at line 2
A is at line: 3
HI
THERE
It reads: GAMMA
A is still at line 3
A is at line: 4
HI
THERE
It reads: DELTA
A is still at line 4

anm
-- 
$ # = "%.6g" ; stat $0 or die $! ;
_ = q.Just another Perl Hacker.  ;
print $ #                        ;
main'_ . v10                     ;



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

Date: Mon, 16 Oct 2000 16:08:10 -0400
From: Jeff Boes <jboes@eomonitor.com>
Subject: Re: question
Message-Id: <39eb6099$0$35020$44a10c7e@news.net-link.net>

>   JS> I've said all I'm going on this subject- so feel free to put your final
>   JS> comments on the above.  I'm sure they'll be be "definitive".
> 
> well, anything will be better than what you have said. and with your fun
> attitude you will just be killfiled by most of the regulars here. have
> fun!

It never ceases to amaze me how often the 'killfile' threat comes up in
discussions on this newsgroup... Far too often, if you ask me.

Think about what you are saying here. "I don't agree with your opinion,
and I think your expression of it is so far off-base that I will refuse
to listen to anything else you EVER have to say about ANY topic.
Lalalala, I can't hear you, lalalala..."

-- 
Jeff Boes <jboes@eoexchange.com>          Tel:  (616) 381-9889 x.18
Sr. Software Engineer, EoExchange, Inc.   http://www.eoexchange.com/
Search, Monitor, Notify.                  http://www.eomonitor.com/


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

Date: 16 Oct 2000 16:30:06 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: question
Message-Id: <m3og0kpm0h.fsf@mumonkan.sunstarsys.com>

"Andrew N. McGuire " <anmcguire@ce.mediaone.net> writes:

> Actually it is open() that closes the file file by implicitly calling
> close() for every open() after the first. ( Thats a mouthful ).

Thanks- I didn't know that!
> 
> [ snip somehow broken test ]
> 
> It works for me. :-)
>

I tried you code verbatim again, and I still get the same 
problem.  I believe that it should work, but here's my output :

% ./test.pl

A is at line: 1
HI
THERE
It reads: ALPHA
A is still at line 0
A is at line: 2
HI
THERE
It reads: BETA
A is still at line 0
A is at line: 3
HI
THERE
It reads: GAMMA
A is still at line 0
A is at line: 4
HI
THERE
It reads: DELTA
A is still at line 0

% perl -v

This is perl, version 5.005_03 built for i386-linux

Are you using a more modern verion? Is there something
in the changelogs about $. and close?

-- 
Joe Schaefer


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

Date: 16 Oct 2000 14:16:51 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: question
Message-Id: <m3r95gvboc.fsf@dhcp11-177.support.tivoli.com>

Joe Schaefer <joe+usenet@sunstarsys.com> writes:

> "Andrew N. McGuire " <anmcguire@ce.mediaone.net> writes:
> > So a natural combination of the two yields:
> > 
> > # $fileB renamed to $file_b
> > 
> > sub action ($) {
> >     local($., *IN);
> >     my $line = shift;
> >     open IN, $file_b or die $!;
> >     1 while <IN>;
> >     return $line;
> > }
> 
> Well done!  However, I think you've forgotten
> an essential piece of the original inplementation
> of action.  In the original "action", each time
> it's called, the entirety of fileB is parsed.
> In Martien's solution, and yours as well, fileB
> is only read the first time that action is called.
> in particular, your code's
> 
> 1 while <IN>;
> 
> line will only be looped through on the first call
> of your "action".  Subsequent calls will bypass this
> line, since you've already read the entire file in,
> but you didn't *close* it in your code.

This is not correct.  An "open" forces an implicit close.  The file is
processed each time.

> This certainly gets $. "right", but for the wrong 
> reason.  I'm still looking for a better solution,
> but I think we're finally getting somewhere on this
> thread.

Having not read news over the weekend and just coming upon this thread
today, and then reading it in its entirety, it is not at all clear
that it is going anywhere.  The solution of localizing $. in the
subroutine was suggested a while back in the thread, and everything
since then hasn't really accomplished anything other than to perhaps
convince you that it actually works.

On the other hand, it does seem to be a valid complaint that if you
have a module that opens and reads from a filehandle, then that module
needs to localize $. (and probably $_), even it the module itself
never makes use of it.  I can see how this could seem problematic, but
I would consider it a bug if it failed to do so.

Note that this is not the only solution to the problem.  You could
also simply localize $. in a bare block that is used to call the
subroutine...

  print "A is at line:$.\n";
  {
    local $.;   # Distant::action has a bug that trounces $.
    print "It reads: " . Distant::action($_);
  }
  print "A still is at line:$.\n";

-- 
Ren Maddox
ren@tivoli.com


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

Date: Mon, 16 Oct 2000 16:23:45 -0400
From: Jeff Boes <jboes@eomonitor.com>
Subject: Re: Regex for matching e-mail addresses
Message-Id: <39eb654a$0$30003$44a10c7e@news.net-link.net>

James Taylor wrote:
> 
> In article <slrn8ugneg.ue5.tjla@thislove.dyndns.org>, Gwyn Judd
> <URL:mailto:tjla@guvfybir.qlaqaf.bet> wrote:
> >
> > Is there a better way to check for a syntactically valid email address?
> 
> I would like to see some examples of *real* email addresses that
> someone would be likely to enter into a web form, for example.

I'm always puzzled about why people bother with this problem. Note that
anyone can enter

  me@example.net

into your form, and while it's a valid address, it certainly isn't a
useful one.

[Ref.: http://www.faqs.org/rfcs/rfc2606.html, section 3]

-- 
Jeff Boes <jboes@eoexchange.com>          Tel:  (616) 381-9889 x.18
Sr. Software Engineer, EoExchange, Inc.   http://www.eoexchange.com/
Search, Monitor, Notify.                  http://www.eomonitor.com/


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

Date: Mon, 16 Oct 2000 11:08:52 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Save As... Popup box
Message-Id: <39EB4434.C8975E69@vpservices.com>

Rob Donovan wrote:
> 
> I have a perl script that picks a file from a dir and then I want it to
> download it from the browser.
> 
> I know who to send HTML to a browser (ie print content-type text/plain..bla
> bla...), but how do I make the browser download a file or pop up the 'save
> as...' box?

Here's the Perl part of the answer:

my $cmd = "however you would do that in any other language";
print $cmd;

This has to do with servers and browsers and content types, not Perl,
try a newsgroup about CGI.

-- 
Jeff


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

Date: Mon, 16 Oct 2000 15:49:39 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Save As... Popup box
Message-Id: <39EB69E3.D0148B9C@home.com>

Rob Donovan wrote:
> 
> I have a perl script that picks a file from a dir and then I want it to
> download it from the browser.
> 
> I know who to send HTML to a browser (ie print content-type
> text/plain..bla bla...), but how do I make the browser download a 
> file or pop up the 'save as...' box?
 
Two points:
1) Despite what you may think, this isn't really a Perl question. It's
   a CGI one, and there are forums specifically for CGI which will
   greet such inquiries more kindly. (i.e. Many of the folks here don't
   like seeing CGI questions in this forum and may flame you for
   posting them.)
2) You don't. What the browser does with a particular content type
   is up to the browser (user), not you. They may choose to save it,
   display it, or launch some application to deal with the data.

-mjc


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

Date: Mon, 16 Oct 2000 20:29:45 +0100
From: "John Plaxton" <19wlr@globalnet.co.uk>
Subject: Saving Textarea to text file
Message-Id: <8sflfv$259$1@gxsn.com>

Hi there All,

I'm new to Perl having spent time on Delphi, so please could someone help.

I'm trying to save a textarea to a text file.

All works fine until I put in a carriage return. Then I find I am only
saving the first line.

Here's my code,  (I'm using cgi.pm)

$htext = $q->param('headtext');
$tempfile="$database.tmp";

 open (TEMP, ">$tempfile") or die "Error opening file: $!\n";
print TEMP "$htext\n";
close(TEMP);

unlink($headerfile)                     || die "Could not delete file! $!";
rename($tempfile,$headerfile) || die "Could not rename file! $!";

This obviously won't work!!

Should $htext be an array of lines?

Thanks for your help, in advance

John




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

Date: Mon, 16 Oct 2000 14:10:23 -0400
From: "Sylvain Perreault" <sylvain2k@sympatico.ca>
Subject: Sorting a list
Message-Id: <ktHG5.3108$My1.86780@wagner.videotron.net>

Hi!

I have this file:

celinedi:Celine Dion - I want you to need me:3:
larafabi:Lara Fabian - I will love again:6:
etc...

I wanna sort it with the second part of each line...

I looked in many websites, books and tested a lot of things... nothing
works!

Thanks a lot!

Sylvain





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

Date: Mon, 16 Oct 2000 20:32:57 +0200
From: Per Kistler <kistler@gmx.net>
To: Sylvain Perreault <sylvain2k@sympatico.ca>
Subject: Re: Sorting a list
Message-Id: <39EB49D9.1FA2BE43@gmx.net>

Like so:

sub mySort {
        my $A = (split(/:/,$a))[1];
        my $B = (split(/:/,$b))[1];
        return $A cmp $B;
}

@data = grep { not /^\s*$/ } <DATA>;
print sort mySort @data;


__DATA__
celinedi:Celine Dion - I want you to need me:3:
larafabi:Lara Fabian - I will love again:6:
test:AAA - BBB:4:
test:ZZZ - BBB:4:

produces:

test:AAA - BBB:4:
celinedi:Celine Dion - I want you to need me:3:
larafabi:Lara Fabian - I will love again:6:
test:ZZZ - BBB:4:


Per.


Sylvain Perreault wrote:
> 
> Hi!
> 
> I have this file:
> 
> celinedi:Celine Dion - I want you to need me:3:
> larafabi:Lara Fabian - I will love again:6:
> etc...
> 
> I wanna sort it with the second part of each line...
> 
> I looked in many websites, books and tested a lot of things... nothing
> works!
> 
> Thanks a lot!
> 
> Sylvain

-- 
Per Kistler, Zuerich, Switzerland
------------------------------------------------------------------------


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

Date: 16 Oct 2000 14:24:30 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Sorting a list
Message-Id: <m1r95g1nu9.fsf@halfdome.holdit.com>

>>>>> "Per" == Per Kistler <kistler@gmx.net> writes:

Per> Like so:
Per> sub mySort {
Per>         my $A = (split(/:/,$a))[1];
Per>         my $B = (split(/:/,$b))[1];
Per>         return $A cmp $B;
Per> }

Per> @data = grep { not /^\s*$/ } <DATA>;
Per> print sort mySort @data;

That's gonna be annoyingly slow for all but the tiniest of lists.  You
should look into a Schwartzian Transform (named after me, but not *by*
me) or the GSR sort (named by the authors after themselves :-).

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 16 Oct 2000 21:30:00 GMT
From: cjw44@flatline.org.uk (Colin Watson)
Subject: Re: Sorting a list
Message-Id: <8sfs0o$4dv$1@riva.ucam.org>

Sylvain Perreault <sylvain2k@sympatico.ca> wrote:
>I have this file:
>
>celinedi:Celine Dion - I want you to need me:3:
>larafabi:Lara Fabian - I will love again:6:
>etc...
>
>I wanna sort it with the second part of each line...

You may not want to do it this way, but, just to show that you can,
here's a (squeezed onto) one-line way using a Schwartzian Transform:

  print join'',map{$$_[0]}sort{$$a[1] cmp $$b[1]}map{[$_,(split /:/)[1]]}<>;

Expanded, that's:

  1) <>
     Read the whole file and return an array of its lines, since this is
     in list context.

  2) map { [$_, (split /:/)[1]] }
     Produce list of array references, each of which points to a line
     and the second field out of that line.

  3) sort { $$a[1] cmp $$b[1] }
     Sort this list by lexicographic comparison of the second element of
     the referenced array, that is, the second field in each line.

  4) map { $$_[0] }
     Map all the array references back to the original list in the new
     order.

  5) join ''
     We never bothered getting rid of newlines, so glue 'em back
     together like this.

  6) print
     Does what it says on the tin.

The way posted by Per Kistler should use less memory (it doesn't build
the list of all the second fields in advance) but be slower (it has to
do two split()s every time the comparison function is called, which will
be O(n log n) times). And, of course, his solution doesn't take as much
explaining if you don't know the idiom. Your mileage may vary.

-- 
Colin Watson                                     [cjw44@flatline.org.uk]
"Racism is generally the last refuge of the unimportant."


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

Date: Mon, 16 Oct 2000 21:32:05 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Sorting a list
Message-Id: <x7n1g4tqui.fsf@home.sysarch.com>

>>>>> "RLS" == Randal L Schwartz <merlyn@stonehenge.com> writes:

  RLS> That's gonna be annoyingly slow for all but the tiniest of lists.
  RLS> You should look into a Schwartzian Transform (named after me, but
  RLS> not *by* me) or the GSR sort (named by the authors after
  RLS> themselves :-).

if you are going to slander us, at least get the acronym correct! it is
the GRT.

:)

and we were looking for a name in public and someone else (i think the
departed abigail) coined the one that was accepted.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: 16 Oct 2000 14:45:43 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Sorting a list
Message-Id: <m1g0lw1muw.fsf@halfdome.holdit.com>

>>>>> "Uri" == Uri Guttman <uri@sysarch.com> writes:

>>>>> "RLS" == Randal L Schwartz <merlyn@stonehenge.com> writes:
RLS> That's gonna be annoyingly slow for all but the tiniest of lists.
RLS> You should look into a Schwartzian Transform (named after me, but
RLS> not *by* me) or the GSR sort (named by the authors after
RLS> themselves :-).

Uri> if you are going to slander us, at least get the acronym correct! it is
Uri> the GRT.

Uri> :)

Uri> and we were looking for a name in public and someone else (i think the
Uri> departed abigail) coined the one that was accepted.

Ooops, no offense intended, on either count.  Was mistaken on the
first, misinformed on the second.  Must be monday. :) :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Mon, 16 Oct 2000 18:06:51 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: Sorting is too slow for finding top N keys... - UPDATE: Clarification.
Message-Id: <8sfg68$opk$1@news.mch.sbs.de>

In article <lzitqs93eb.fsf@linuxsexi.neuearbeit.de>, mriedel@neuearbeit.de (Marko R. Riedel) wrote:
>
>The thread that I refer to contains the message
><lz1zg7d7zm.fsf@linux_sexi.neuearbeit.de>, for example.

To summarize, I was trying to get the top N elements
of a list (or rather, the keys corresponding to the top N
values of a hash), and got incredibly long response times
with the standard sort & slice approach.
It turned out that this was mostly due to excessive
swapping on the system (and an old perl version).

Several interesting approaches were given by different
people, including the quickselect algorithm mentioned
by Marko.

If you've had a similar problem or are interested in algorithms,
you can check out the whole thread at :
http://x62.deja.com/threadmsg_ct.xp?AN=475612738.1

Michel.


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

Date: Mon, 16 Oct 2000 18:30:15 GMT
From: hankahn2@my-deja.com
Subject: Spawning Perl Processes From Perl
Message-Id: <8sfhfo$s4r$1@nnrp1.deja.com>

How do I make it so that a perl script can start other perl scripts?  I
don't care if these scripts come back.  Actually I want the perl script
to keep going right after it starts off the process.  Also there will
be many processes started by this one script.  Thanks in advance for
your help.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 16 Oct 2000 16:46:22 -0400
From: aperrin@demog.berkeley.edu (Andrew J. Perrin)
Subject: Re: Spawning Perl Processes From Perl
Message-Id: <ulmvo5xb5.fsf@demog.berkeley.edu>

hankahn2@my-deja.com writes:

> How do I make it so that a perl script can start other perl scripts?  I
> don't care if these scripts come back.  Actually I want the perl script
> to keep going right after it starts off the process.  Also there will
> be many processes started by this one script.  Thanks in advance for
> your help.

It's really not necessary to post the same question twice.

perldoc -f fork

-- 
----------------------------------------------------------------------
Andrew Perrin - Solaris-Linux-NT-Samba-Perl-Access-Postgres Consulting
       aperrin@igc.apc.org - http://demog.berkeley.edu/~aperrin
----------------------------------------------------------------------


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

Date: Mon, 16 Oct 2000 11:11:33 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: split problem
Message-Id: <39EB44D5.27C7542A@stomp.stomp.tokyo>

Ren Maddox wrote:
 
> homer.simpson@springfield.nul (Homer Simpson) writes:
 
> > Andrew N. McGuire (and others) recommended:
> > use Text::ParseWords;

> > rather than:
> > Homer Simpson wrote:

> > HS> >234,tree,"Smith, John",6834
> > HS> >The problem I face is how to get split to ignore the comma inside the
> > HS> >quotation marks.

> > Assuming the string is held in variable $in:

> >  $in[2]=join('',$in[2],$in[3]);
> >         @in=@in[0,1,2,4];

> > I looked up Text::ParseWords;
> > It seems that my two lines of code would do the job in fewer keystokes...

> > Since the format of the data is known and static is there a reason to prefer
> > Text::ParseWords?  Or is there a flaw I missed in my snippet?
 
> The OP stated that the file contains one line like the above, not that
> all lines were like the above.  The code you have provided works only
> for that specific type of data.  The presumption that others are
> making is that there may be other similar data and that a more general
> solution is desired.  Text::ParseWords is one such solution.


Why would you make a presumption other data is different
or even make a presumption there is other data lacking any
evidence to support either presumption? You are changing
parameters to fit your presumption, not making a presumption
based upon stated parameters.


 
> Plus, it isn't really any longer...
 
> #!/usr/local/bin/perl -w
> use strict;
> use Text::ParseWords;
> chomp(my @fields = quotewords(",", 1, <DATA>)); # inefficient but terse chomp
> print "$_\n" for @fields;
> __DATA__
> 234,tree,"Smith, John",6834
> __END__


What amount of memory bloat is incorporated by
use of text ~ parsewords and, how much slower
would a script run using text ~ parsewords?

You are making a presumption, an extra line of
code, a few extra lines of code makes no difference
although you are invoking use of a module. You are
ignoring using a module to validate your presumption. 



Godzilla!
-- 
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class


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

Date: Mon, 16 Oct 2000 16:12:07 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: split problem
Message-Id: <39EB6F27.744E3431@home.com>

"Godzilla!" wrote:
> 
> Neo James Crum wrote:
> 
> > ...I have a line like follows:
> 
> > 234,tree,"Smith, John",6834
> 
> > ...how to get split to ignore the comma inside the
> > quotation marks.
> 
> Do not respond with changed parameters and,
> "This does not work."

Bah. Is that how you're attempting to justify your coding now? By that
line of reasoning I could submit that this is a perfectly acceptable
solution:

my $line = '234,tree,"Smith, John",6834';
my @split_line = (
    234,
    'tree',
    'Smith, John',
    6834,
);

[snip of poor solution]

You're making two large assumptions about the formatting of the input
data: that quoted commas are always followed by a space and that the
source data does not already contain the © character.

Furthermore, the quotes are not part of the data, they're part of the
formatting. A proper split should remove them as such.

Neo, as others have suggested, use one of the modules designed for this
task and ignore the raving reptile.

-mjc


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

Date: Mon, 16 Oct 2000 18:27:42 GMT
From: hankahn2@my-deja.com
Subject: Starting Background Processes With PERL
Message-Id: <8sfhak$s16$1@nnrp1.deja.com>

I have a script that I want to spawn off other
perl scripts.  I don't care if they ever come
back I just want them to start.  These jobs will
take a long time to complete so I want the perl
script to keep on going after it starts the
process.  Thanks in advance for your help.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Mon, 16 Oct 2000 17:30:56 -0300
From: "Luis E. Rodriguez" <nospam@luisr@juanadiaz.org>
Subject: Substracting one list from another
Message-Id: <ruKG5.23098$Kx.1664152@e420r-sjo1.usenetserver.com>

Hi there!  I am looking for a way to substract one list from another in
PERL.  I searched this newsgroup, the PERL FAQs and did not find anything
that could answer my question.

The lists in question result from a search routine.  The search is performed
on a large hash (stored in a db file) and the search results is a list of
all the hash keys that met the search criteria.  However, there is a second
list containing a number of keys that should be excluded from the results.
The elements of the second list must be substracted from the results list.
It is not just a matter of removing duplicates.

I could handle this with a loop but would be inefficient because the search
results can contain thousands of results while the exclusion list might
contain just a couple hundred elements.

Is there a grep construct or some other way to do this efficiently?

Thanks.

Please reply here and also via e-mail if possible at
nospam@luisr@juanadiaz.org.  Remove the nospam@ part, of course.






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

Date: Mon, 16 Oct 2000 15:59:29 -0600
From: "Darryl Friesen" <Darryl.Friesen@usask.ca>
Subject: Re: Substracting one list from another
Message-Id: <8sftmt$l6j$1@tribune.usask.ca>


"Luis E. Rodriguez" <nospam@luisr@juanadiaz.org> wrote in message
news:ruKG5.23098$Kx.1664152@e420r-sjo1.usenetserver.com...

> Hi there!  I am looking for a way to substract one list from another in
> PERL.  I searched this newsgroup, the PERL FAQs and did not find anything
> that could answer my question.

Look in the FAQ for union and intersection of lists/hashes.  I'm almost
positive there's examples of this.


- Darryl

 ----------------------------------------------------------------------
  Darryl Friesen, B.Sc., Programmer/Analyst    Darryl.Friesen@usask.ca
  Education & Research Technology Services,     http://gollum.usask.ca/
  Department of Computing Services,
  University of Saskatchewan
 ----------------------------------------------------------------------
  "Go not to the Elves for counsel, for they will say both no and yes"





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

Date: Mon, 16 Oct 2000 20:45:40 GMT
From: trollis@my-deja.com
Subject: Telling difference between a package and a class?
Message-Id: <8sfpdi$3kl$1@nnrp1.deja.com>

Hi,

I'm trying to identify whether a file is a Perl package or a class.
I have been thinking about checking for "@ISA" or "sub new", but either
could exist for both types, right? So, is there a proper way to do it?
Is there a near catch-all way to do it, e.g. 90% of all packages have
no "new" sub?

Regards,

/Gunnar
--


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Mon, 16 Oct 2000 17:50:48 -0500
From: "Louis Z" <louis@trapezoid.com>
Subject: Threads and SMP
Message-Id: <39eb78d3$1_2@goliath2.newsfeeds.com>

Thank you all for the help.  Allow me to be more specific in my
question...

Does Perl support any message passing between threads?  I can use fork to
duplicate the running process, but unless the two are working togehter,
then they are just competing for the same CPU cycles.

I'm working on Cellular Automata simulations and I wanted to have the two
CPUs each work on half of the CA Space, and then the master thread would
re-assemble the final result and assign new work to the slave threads.  If
my understanding of multithreading is wrong, then please correct me.

					Thanks again,
					Louis Z <louis@trapezoid.com>

In article <39db8787$1_3@goliath2.newsfeeds.com>, "Louis Z"
<louis@trapezoid.com> wrote:
> Is there any way for Perl to take advantage of dual CPUs?  Using
> threads?  Ideally, I'd be able to run some simulation programs twice as
> fast if they could' use both CPUs.  Thanks.
> 
> 					-Louis Z <louis@trapezoid.com>
> 
> 
> 
> -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> -----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


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

Date: Mon, 16 Oct 2000 18:36:31 GMT
From: lorddcee@my-deja.com
Subject: Tracking user in perl CGI... HELP!
Message-Id: <8sfhre$si8$1@nnrp1.deja.com>

Tracking user in perl CGI... HELP!

Hi!

I've just started using Perl (and CGI Too.. ), so please, be gentle :)


So, I need to keep track of my users during their sessions, I've read
chapter 11 of the mouse book (CGI perl programming), and, I find the
way they offer pretty heavy to use... (the one that calls a CGI each
time a page is accessed...)

Is there any easier, or, better, or... just tell me what you use! to
keep track of the session of a user... (god i miss the session
Object...)

Thanks in advance!

Someone who needs help! :)


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Mon, 16 Oct 2000 15:06:59 -0400
From: "Phil R Lawrence" <prlawrence@lehigh.edu>
Subject: Re: Tracking user in perl CGI... HELP!
Message-Id: <8sfjig$83e@fidoii.CC.Lehigh.EDU>


<lorddcee@my-deja.com> wrote:
> Tracking user in perl CGI... HELP!
>
> Hi!
>
> I've just started using Perl (and CGI Too.. ), so please, be gentle :)
>
>
> So, I need to keep track of my users during their sessions...
> Is there any easier, or, better, or... just tell me what you use! to
> keep track of the session of a user... (god i miss the session
> Object...)

I got a lot out of Randall's Web Techniques columns, this one might help
you:
http://www.stonehenge.com/merlyn/WebTechniques/col23.html

Phil R Lawrence




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

Date: 16 Oct 2000 14:12:00 -0400
From: Walt Mankowski <walt@myxa.com>
Subject: Re: What is wrong with this subroutine?
Message-Id: <lnpul03bbj.fsf@myxa.com>

Geoff Soper <g.soper@soundhouse.co.uk> writes:

> It's the split_csv subroutine which is causing the problem. 

Then you should read the discussion on parsing CSV files in perlfaq4.


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

Date: Mon, 16 Oct 2000 20:06:41 +0100
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: What is wrong with this subroutine?
Message-Id: <ant1619410e6fNdQ@oakseed.demon.co.uk>

In article <4a0e6f5483g.soper@soundhouse.co.uk>, Geoff Soper
<URL:mailto:g.soper@soundhouse.co.uk> wrote:
>
> # Separate any quote-enclosed records, process both types
>
> foreach $segment (split(/("[^"]*"),* */, $record)) {        
>     if ($segment =~ /^"(.*)"$/) { push(@fields, $1) }
>     else { push(@fields, split(/, */, $segment)) }
> }

Your first split doesn't appear to cope with embedded quotes
in the style of "He said ""Hello"" to her". Consecutive commas
after a quoted field are discarded, as are spaces between commas.
Leading commas do find their way into $segment though, but then
the second split expands them into the wrong number of fields.
There doesn't appear to be any handling of backslash escapes
either, but then perhaps you're doing that later. All in all,
I'm amazed it worked for you at all, but perhaps you had a very
limited subset of CSV to handle in the past.

My suggestion would be to use one of the CSV parsing modules on
CPAN. I think there's one called Text::CSV but I've not used it
myself.

-- 
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02



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

Date: Mon, 16 Oct 2000 14:24:18 -0400
From: Don <don@lclcan.com>
Subject: Re: XBase module
Message-Id: <39EB47D1.AB47840A@lclcan.com>

> > For any one familiar with the DBD XBase module, here is my code:
> >
> > my $port_table = new XBase "/home/ftpadmin/pub/ports.dbf";
> > my $port_ndx =
> $port_table->prepare_select_with_index("/home/ftpadmin/pub/ports.dbf");
> >
> > I get the following error message in the log file:
> > can't call method "prepare_select_with_index" on an undefined value at
> > /home/httpd/cgi-bin/myfile.cgi line 230
> >
> > The files exist. Can anyone explain the error or point me to the
> > documentation?
>
> You should almost certainly be using DBD::XBase.pm instead of XBase.pm
> and the documentation for it is under perldoc "DBD::XBase", no tunder
> "perldoc XBase".  In any case, whenever you open a file or database, you
> should use error checking to report any problems in the opening
> process.  If your script tells you your'e using method x() on an
> undefined value, that means that whatever object $y you are tyring in a
> statement of the form $y->x() is undefined, and therefore, in this case
> unopened.
>

Done and fixed, thanks.  Now another problem.  After I open my dbf and ndx
files, I execute the following line of code which is according to the manual:

$port_ndx->find_eq($port_field);

where $port_field is equal tosome character string.  upon executing the
script, it seems to hang.  no log entry in the error file but I have
tokillthe process.

Any idea why?



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

Date: Mon, 16 Oct 2000 11:37:11 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: XBase module
Message-Id: <39EB4AD7.D11683F7@vpservices.com>

Don wrote:
> 
> $port_ndx->find_eq($port_field);
> 
> where $port_field is equal tosome character string.  upon executing the
> script, it seems to hang.  no log entry in the error file but I have
> tokillthe process.

Sorry, I never use XBase by itself, I only use DBD::XBase.  Isn't there
any error checking method, there certainly is in DBD::Xbase.

-- 
Jeff


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

Date: Mon, 16 Oct 2000 13:13:49 -0500
From: "Jim Gaasedelen" <jim@usjet.net>
Subject: Re: XSL (from CGI) not kept on server?
Message-Id: <1zHG5.589$pL5.156613@news.uswest.net>

You can store the XSL where ever you want, can't you? The following line
demonstrates:
<?xml-stylesheet type="text/xml" href="14-2.xsl"?>
The href= could easily be href="http://someplace-else.com/docs/14-2.xsl"?>
But if you are coming out of a database, you might be able to just do the
transformation in SQL (depending on what DB you
are using).  You have not provided quite enough information to answer your
question well.
I hope this helps a little.


<spwnet@mailcity.com> wrote in message news:8rsng1$28q$1@nnrp1.deja.com...
> I want to create an XML file dynamically for one of several formats
> (magazines, books, newspapers etc) and can do this quite easily
> with a Perl CGI script, given a data file with the field names as well
> as the actual records:
>
> e.g. data file for books:
>
> BookTitle,AuthorSurname, PublisherID, YearOfPub, Format
> Lord Of The Rings,Tolkien,Unwin,1966,PB
>
> e.g. data file for magazines:
>
> Title,PublisherID,YearOfPub,VolNumber,IssueNumber
> New Scientist,IPC,2000,100,12
>
> When the XML is generated it is sent to the client.  All fine so far.
> However, for space and security reasons I don't want to store the
> XSL on the server.  Is it possible to dynamically generate XSL via a
> Perl CGI script so that the XSL is accessible to the client but is NOT
> stored on the serving computer?  (eg making the XSL inline somehow with
> the XML?)
>
> Sean
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.




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

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 4633
**************************************


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