[13547] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 957 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 30 19:07:16 1999

Date: Thu, 30 Sep 1999 16:05:17 -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: <938732717-v9-i957@ruby.oce.orst.edu>
Content-Type: text

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

Today's topics:
    Re: #exec cgi <cassell@mail.cor.epa.gov>
    Re: a question of buttons <davids@desertigloo.com>
    Re: acos function <cassell@mail.cor.epa.gov>
    Re: acos function <cassell@mail.cor.epa.gov>
    Re: Bye Tom? (WAS: Re: injecting "my" varibales into ca <AgitatorsBand@yahoo.com>
    Re: Calling a subroutine held at one sever from another <cassell@mail.cor.epa.gov>
    Re: Calling Gunzip (Gzip) from Perl <cassell@mail.cor.epa.gov>
    Re: Catching errors in anouther name space. <admin@gatewaysolutions.net>
    Re: form to mail script for NT <cassell@mail.cor.epa.gov>
    Re: help reading multi-line text file <koharik@primenet.com>
    Re: help reading multi-line text file <vincent.murphy@cybertrust.gte.com>
    Re: help reading multi-line text file <sariq@texas.net>
    Re: help reading multi-line text file (Larry Rosler)
        help with simple interactivity albuck@my-deja.com
        Help with this Crazy script! alex_rayan@my-deja.com
    Re: HTML to ASCII <cassell@mail.cor.epa.gov>
    Re: numeric sort on field 2 in @array... <arthur.haas@westgeo.com>
    Re: numeric sort on field 2 in @array... (Larry Rosler)
    Re: numeric sort on field 2 in @array... <shiloh@shell9.ba.best.com>
    Re: numeric sort on field 2 in @array... <sariq@texas.net>
    Re: numeric sort on field 2 in @array... <uri@sysarch.com>
    Re: numeric sort on field 2 in @array... <cassell@mail.cor.epa.gov>
    Re: numeric sort on field 2 in @array... (Larry Rosler)
    Re: numeric sort on field 2 in @array... <shiloh@shell9.ba.best.com>
    Re: Perl AI Apps/Expert Systems <cassell@mail.cor.epa.gov>
    Re: RegEx for html->plain text <sjohns17@uic.edu>
    Re: Suggestion - comp.lang.perl.flame (was Re: You shou (Eric Bohlman)
    Re: Thread.pm <cassell@mail.cor.epa.gov>
        Upload problem w/ Apache/Linux/CGI.pm j_v_schmitt@my-deja.com
    Re: Using SS Numbers as DBM Index: Best Way to Encrypt  <cassell@mail.cor.epa.gov>
        Wrong value returned when accessing list using scalar v geotekjohn@my-deja.com
    Re: You should be admired <menolly@spy.net>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 30 Sep 1999 15:43:33 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: #exec cgi
Message-Id: <37F3E795.7647FFC@mail.cor.epa.gov>

kcyu@psu.edu wrote:
> 
> Hi,

Howdy,
 
>   I've tried to pass parameters to SSI's cgi.
> 
> For Example - http://mydomain/myshtml.shtml?querystring,
> in Apache, it will pass to <!--#exec cgi="script.cgi"--> which in
> myshtml.shtml
> but in IIS 4.0, it seems it doesn't pass paramenters the cgi!?
> 
> Does anybody know how to enable IIS 4.0 to pass the argument?
> Or it is impossible in IIS.

Since your problem is so server-specific, you'll get more
help asking in a newsgroup devoted to web servers, or one
specifically about IIS 4.0 .  Even though you want to include
a Perl script, your problem really has nothing to do with
the language of your CGI script.  So you'll get better help
somewhere else.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Thu, 30 Sep 1999 15:48:16 -0700
From: "David P. Schwartz" <davids@desertigloo.com>
Subject: Re: a question of buttons
Message-Id: <37F3E8B0.53EA5E01@desertigloo.com>

Thank you, Jason.  I got get sufficient replies here, and so I saw no need to take
the question anywhere else.  I did, however, post a question in the group you
referenced that I'd posted here and got no replies.  So, thank you again for the
pointer.

The way I program, I design my data structures and internal flow, then I create some
kind of a user-interface that maps onto it.  I suppose that's how I was taught in
school.  That was certainly how one developed GUI-based apps until visual
development tools came along and became really popular about 5 years or ago.

Perl is fairly new to me, but I'm familiar with awk, sed, and a lot of other unix
tools, as well as c, c++, and most recently Delphi.  HTML is a brain-dead language.
All the work needs to happen on the Perl side (or whatever language one chooses to
use), unless one wants to get into javascript or Java, which I'm not too keen on at
this point in time.

Again, I'm sorry that my programming style doesn't fit with what people here believe
is "appropriate".  Since I'm working in Perl, that's how I'm viewing things, and
this is ostensibly a Perl newsgroup.  Given that, I appreciate those who've taken
the time to provide useful and helpful replies, even if it seems to go against the
grain.  Ultimately, I see virtually no difference between writing a piece of Perl
code that happens to contain HTML-formatted text that's sent to something that ends
up on a user's monitor and then deals with a response, versus wrting some code that
puts the same stream of characters into a file and reads something back later.  The
only difference of any significance, in fact, appears to be the OPEN statement
that's used.  The rest is all subject to higher levels of interpretation.  To me,
it's just a Perl program that might or might not work as desired.

Finally, I just "popped in" here recently after being pointed here by someone else
while attempting to resolve another question.  I have no sense of "history" the way
many folks do who've been lurking here and supporting others for a long time.
Messages do not have an attribute attached to them with a "grade" or "rank" or
something that indicates how long they've been around.  Inappropriate communication
occurs sometimes (some think THIS is, I suppose).  People who are newcomers to any
group have no a priori data to tell them who's "got a clue" and who doesn't.  This
is no different than walking into a group of people you don't know at a social
gathering.  Someone could be the President of IBM, say.  But if he/she is being
inappropriate, it doesn't matter WHO they are to a stranger.  The point is, we seem
to have a agreement in our culture that people with more status or stature are
ALLOWED to be more extreme, I suppose.  Sorry, I don't buy into it.

So, I'm complete here.  I won't post any further responses to this thread.  I want
to thank everybody for their patient and tolerant responses, as well as those who
attempted to "keep the law" in spite of their tone.

-David



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

Date: Thu, 30 Sep 1999 15:38:42 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: acos function
Message-Id: <37F3E672.945986C2@mail.cor.epa.gov>

jmn.ac.delete@abanet.it wrote:
> 
> >> Has anyone a acos (cos-1, arccos) function for Perl.
> >
> >> I am lazy.
> >
> >You're obviously even too lazy to read the doc
> >acos is in perldoc -f cos
> >
> 
> This group is TESTY.

Yes.  That's our watchword.  Testiness and fear.  Umm, our
*two* watchwords.  Testiness and fear and...

> I read the docs. They say POSIX::acos. A discussion of why I don’t want to use the POSIX module will not be helpful.
> 
> As for laziness, hasn’t it been beatified by the Camel book? And anyway I am not that lazy; here is an acos function for anyone who might be interested.

Laziness is Larry Wall's "First Great Virtue of a Programmer"
But that's *his* definition of laziness, not yours.
His def says: "the quality that makes you go to great effort to
reduce overall energy expenditure."

So, writing a nice acos() sub with comments and giving it to
everyone on Usenet *is* Laziness.  The good kind.

But I would have used my() on each of your a_sub_i in your
sub below...

> sub acos {
>     # Polynomial approximation of acos
>     # Error <= 2E-8
>     #
>     # C. Hastings, Jr., "Approximations for digital computers",
>     # Princeton Univ. Press, 1955.
> 
>     my $x = shift @_;
>     $a0 =   1.5707963050;
>     $a1 =  -0.2145988016;
>     $a2 =   0.0889789874;
>     $a3 =  -0.0501743046;
>     $a4 =   0.0308918810;
>     $a5 =  -0.0170881256;
>     $a6 =   0.0066700901;
>     $a7 =  -0.0012624911;
> 
>     return (1-$x)**0.5 *($a0
>                          + $a1 * $x
>                          + $a2 * $x**2
>                          + $a3 * $x**3
>                          + $a4 * $x**4
>                          + $a5 * $x**5
>                          + $a6 * $x**6
>                          + $a7 * $x**7
>                         );
> }

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Thu, 30 Sep 1999 15:41:19 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: acos function
Message-Id: <37F3E70F.8B856065@mail.cor.epa.gov>

jmn.ac.delete@abanet.it wrote:
> 
> Alex Rhomberg <rhomberg@ife.ee.ethz.ch> wrote:
> 
> >    sub acos { atan2( sqrt(1 - $_[0] * $_[0]), $_[0] ) }
> 
> Thanks, this was what I was looking for. All that I can say in my defense is that this isn't mentioned in my 5.002 distribution or in the Camel Book.

I like the Camel.  But it is not the first place you should
look for documentation.  First check the docs on your own
computer, since they'll be as up-to-date as your own copy of
Perl.

As an example, the Camel is seriously out-of-date re the
things you can do with regexes.  Look in the perlre 'manpage'
to see a host of patterns unavailable when the Camel was
written...

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Thu, 30 Sep 1999 22:08:30 GMT
From: Scratchie <AgitatorsBand@yahoo.com>
Subject: Re: Bye Tom? (WAS: Re: injecting "my" varibales into callers scope)
Message-Id: <ybRI3.105$QB2.20068@news.shore.net>

Abigail <abigail@delanet.com> wrote:
: Scratchie (AgitatorsBand@yahoo.com) wrote on MMCCXXI September MCMXCIII
: in <URL:news:07NI3.72$QB2.11160@news.shore.net>:
: !! 
: !! What are you implying? That because Tom has contributed a lot of work to
: !! the perl community that we should pretend that he isn't a condescending
: !! jerk when he posts?


: You don't have to pretend that, as he isn't.

Not compared to you, I guess?

--Art
-- 
--------------------------------------------------------------------------
                    National Ska & Reggae Calendar
                  http://www.agitators.com/calendar/
--------------------------------------------------------------------------


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

Date: Thu, 30 Sep 1999 15:55:33 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Calling a subroutine held at one sever from another
Message-Id: <37F3EA65.672B2642@mail.cor.epa.gov>

C. Gaunt wrote:
> 
> Is it possible to call a subroutine that is is the cgi-bin on one
> sever from a perl script in the cgi-bin of a second server.
> I tried:
> server1
> # hello.pl
> sub say_hello {
>   print "Content-type: text/html\n\n";
>   print "Hello from server1.com\n";
> }
> 
> server2
> #!/usr/bin/perl
> require "http://www.server1.com/cgi-bin/hello.pl;
> &say_hello;
> 
> It did not work. error log reports cannot find
> http://www.server1.com/cgi-bin/hello.pl

If you want to send the browser to the new page, just
re-direct.  If you want to read in that page and then
execute the Perl code in there, you'll need to do something
else.  require() and open() assume you have a filesystem.
You have an HTTP connection to a distant webpage.
You could use one of the LWP::* modules to snag the webpage,
then post-process it, then eval() it.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Thu, 30 Sep 1999 15:49:26 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Calling Gunzip (Gzip) from Perl
Message-Id: <37F3E8F6.844679D6@mail.cor.epa.gov>

brad@quicomm.com wrote:
> 
> Has anyone successfully been able to use gzip in a Perl script called
> from a browser?  If so, details are much appreciated.
> 
> We have run into a seemingly weird problem in calling gzip (compression
> app) from Perl.  The problem is that the script runs fine when called
> from a command line.  The script also runs partially when called from a
> browser.  It is just the call to the gzip app does not return anything
> when called from the browser (at this stage, we are just trying to
> return the gunzip licensing message, -L option).
> 
> When we replace gzip with zip (another compression app), the script
> works fine in both command line and browser calls, returning the full
> Licensing statements.

Backticks are going to dump the contents of STDOUT to your
variable.  My PSI::ESP module suggests that... hmm...
It may be that gzip -L dumps the help screen to STDERR instead.
Just something to try...

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

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


Tom Phoenix <rootbeer@redcat.com> wrote in message
news:Pine.GSO.4.10.9909301242060.17231-100000@user2.teleport.com...
> On Wed, 29 Sep 1999, Scott Beck wrote:
>
> > See if you can figure out where it is crashing.
> >
> > <CODE>
> > #!/usr/bin/perl -w
> >
> > use CGI::Carp 'fatalsToBrowser';
>
> Maybe (just maybe) this isn't doing what you think it's doing. Perhaps
> it's not installed correctly, for example.
>
> There are other ways to do this, but for debugging, I
> sometimes put something like this near the top of a script.
>
>     # Remove this block when done debugging!
>     BEGIN {
> local($|) = 1; # Temporarily turn off buffering
> print "Content-type: text/plain\n\n";
> my $date = localtime;
> print "Script $0\nrunning on $date (Perl version $])\n\n";
> unless (open STDERR, ">&STDOUT") {
>     print "Can't redirect STDERR: $!";
>     exit;
> }
> print "\n";
>     }
>
> Now you should be able to see any error messages (and everything else)
> produced by your script, right on your browser.
>
> Good luck with it!
>
> --
> Tom Phoenix       Perl Training and Hacking       Esperanto
> Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/
>
>

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.

Thanks,
Scott



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

Date: Thu, 30 Sep 1999 15:52:28 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: form to mail script for NT
Message-Id: <37F3E9AC.D940C3F3@mail.cor.epa.gov>

jlburnham@my-deja.com wrote:

> Use the Net::SMTP module.  Here's a link that
> explains it:
> http://www.activestate.com/ActivePerl/docs/Perl-
> Win32/perlwin32faq4.html
> See link that says "How do I send email from Perl
> for Win32?"

I would think that Mail::Sender would be a lot easier for a
beginner to grok.  Or Mail::Mailer.

Mail::Sender is also mentioned in the FAQ you cited.

And the FAQ should be on everyone's hard drive by now.
Using the web to read the FAQ is fairly inefficient when
it comes free with every install.  And ActiveState also
gives an HTML version which it drops on the user's 
Start Menu.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Thu, 30 Sep 1999 15:14:06 -0700
From: Chris Koharik <koharik@primenet.com>
Subject: Re: help reading multi-line text file
Message-Id: <Pine.BSI.3.96.990930150223.5621C-100000@usr09.primenet.com>

> Date: Thu, 30 Sep 1999 14:37:45 -0700
> From: mikej <mikej@1185design.com>
> 
> Hi,

Hi back.

> I have a text file (demo.log) of the format:
> 
> 1:180.1.133.52:Thu:Sep:30:1999:10:45:14:email:mikej@1185design.com:firstname:mike:lastname:judkins
> 
> 2:180.1.133.52:Thu:Sep:30:1999:10:46:14:email:vrossi@1185design.com:firstname:valentino:lastname:rossi
> 
> 3:180.1.133.52:Thu:Sep:30:1999:10:47:14:email:mdoohan@1185design.com:firstname:michael:lastname:doohan
> 
> 4:180.1.133.52:Thu:Sep:30:1999:10:48:14:email:mkroberts@1185design.com:firstname:kenny:lastname:roberts
> 
> 5:180.1.133.52:Thu:Sep:30:1999:10:49:14:email:tharada@1185design.com:firstname:tetsuya:lastname:harada
> 
> I am trying to read this data into an array, and then print the last
> names (item 14 of each line) of each line into a text file. The problem
> is that even though I have a foreach loop that should go through each
> line of the text file and print the 14th item, it is only reading the
> first line and nothing else on the lines below. Heres my subroutine:
> 
> sub dolist {
> 
> #$count is a variable I use to see how many times the foreach loop runs
> my $count = 0;
> 
> #extract data from stats file (format shown above)
>  open(LOG, "demo.log") || &error("Couldn't open stats log file \n\n$!");
> 
>  @indata = <LOG>;
>  close(LOG);
>  
> #create a text file with the last names in a list
>  open(LIST, ">list.txt") || &error("Couldn't create list file \n\n$!");
>  
> #get the stats on each line
> #this is where I am trying to get the last names from each line, but it
> only seems to read the first line
> 
>  foreach $line (@indata)
> {
>     chomp($line);
>     @mystats = split(/\:/, $line);
>     #add to $count to see how many times it goes through the foreach
> loop
>     $count = $count + 1;

Easier way:  $count++;

>     #print the 14th item of each line
>     print LIST "$mystats[14]\n";
> }

Don't you mean 15th item (the data for lastname)?  Element numbering
starts at 0.

>     print LIST "read $count lines";
> 
>  close LIST;
> 
> print "Location: list.txt\n\n";
> 
> }
> 
> The end result of the printed text file (list.txt) is that I get the
> last name of the first line only, and the value of $count is equal to 1,
> which tells me its not running the foreach loop enough times to get to
> the rest of the lines. How can I make it go through and return the 14th
> item on all the lines of the demo.log file, instead of just the first?
> 
> mike

Here is my shot at the solution (in Perl):

#!/bin/perl -w

use strict;
my $count = 0;
my @line = ();

open(FILE,"demo.log") or die "Cannot open file: $!";
open(LIST,">list.txt") or die "Cannot open list: $!";
while(<FILE>) {
  chomp(@line =  split(/:/));
  print LIST $line[14] . "\n";
  $count++;
}

close FILE or die "Cannot close file: $!";
close LIST or die "Cannot close list: $!";
print STDOUT "$count records processed.\nOutput in list.txt.\n";

Or, my solution using awk:

cat demo.log|awk -F: '{print $15}' > list.txt

HTH

(Putting flame retarding underpants on)

-Chris



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

Date: Thu, 30 Sep 1999 22:15:47 GMT
From: Vincent Murphy <vincent.murphy@cybertrust.gte.com>
Subject: Re: help reading multi-line text file
Message-Id: <xjgr9jgqc4t.fsf@gamora.ndhm.gtegsc.com>

>>>>> "mikej" == mikej  <mikej@1185design.com> writes:

    mikej> Hi,
    mikej> I have a text file (demo.log) of the format:

<-snip->

    mikej> I am trying to read this data into an array, and then print the last
    mikej> names (item 14 of each line) of each line into a text file. The problem
    mikej> is that even though I have a foreach loop that should go through each
    mikej> line of the text file and print the 14th item, it is only reading the
    mikej> first line and nothing else on the lines below. Heres my subroutine:

    mikej> sub dolist {

    mikej> #$count is a variable I use to see how many times the foreach loop runs
    mikej> my $count = 0;

    mikej> #extract data from stats file (format shown above)
    mikej>  open(LOG, "demo.log") || &error("Couldn't open stats log file \n\n$!");

    mikej>  @indata = <LOG>;
    mikej>  close(LOG);
 
    mikej> #create a text file with the last names in a list
    mikej>  open(LIST, ">list.txt") || &error("Couldn't create list file \n\n$!");
 
    mikej> #get the stats on each line
    mikej> #this is where I am trying to get the last names from each line, but it
    mikej> only seems to read the first line

    mikej>  foreach $line (@indata)
    mikej> {
    mikej>     chomp($line);
    mikej>     @mystats = split(/\:/, $line);
    mikej>     #add to $count to see how many times it goes through the foreach
    mikej> loop
    mikej>     $count = $count + 1;
    mikej>     #print the 14th item of each line
    mikej>     print LIST "$mystats[14]\n";
    mikej> }
 
    mikej>     print LIST "read $count lines";

    mikej>  close LIST;

    mikej> print "Location: list.txt\n\n";

    mikej> }

    mikej> The end result of the printed text file (list.txt) is that I get the
    mikej> last name of the first line only, and the value of $count is equal to 1,
    mikej> which tells me its not running the foreach loop enough times to get to
    mikej> the rest of the lines. How can I make it go through and return the 14th
    mikej> item on all the lines of the demo.log file, instead of just the first?

    mikej> mike
 
I have tried the same thing and it seems to work for me.  Don't know
exactly your problem but the following works:

my( $input ) = 'demo.log';
open( DEMO, $input ) or die;
my( @indata ) = <DEMO>;
close DEMO;
my( @stats );
my( $count ) = 0;
open(LIST, ">list.txt") || die;
foreach ( @indata )  {
    next if /^\s*$/;  # ignore blank lines.
    chomp;
    $count++;
    @stats = split ':';
    print LIST $stats[14], "\n";
}
print LIST $count, "\n";

Not that I don't believe you,  

--Vinny
When this load is DONE I think I'll wash it AGAIN..


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

Date: Thu, 30 Sep 1999 17:18:28 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: help reading multi-line text file
Message-Id: <37F3E1B4.43DFD6BD@texas.net>

mikej wrote:
> 
> Hi,
> 
> I have a text file (demo.log) of the format:
> 
> 1:180.1.133.52:Thu:Sep:30:1999:10:45:14:email:mikej@1185design.com:firstname:mike:lastname:judkins
> 
> I am trying to read this data into an array, and then print the last
> names (item 14 of each line) of each line into a text file. The problem
> is that even though I have a foreach loop that should go through each
> line of the text file and print the 14th item, it is only reading the
> first line and nothing else on the lines below. Heres my subroutine:
> 

<snipped subroutine>

The subroutine will do what you want to do, except that somewhere else
you've likely mucked with one or more of Perl's special variables.

- Tom


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

Date: Thu, 30 Sep 1999 15:42:30 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: help reading multi-line text file
Message-Id: <MPG.125d872d4f3fdaf098a010@nntp.hpl.hp.com>

In article <xjgr9jgqc4t.fsf@gamora.ndhm.gtegsc.com> on Thu, 30 Sep 1999 
22:15:47 GMT, Vincent Murphy <vincent.murphy@cybertrust.gte.com> says...
> >>>>> "mikej" == mikej  <mikej@1185design.com> writes:

 ...

>     mikej>  @indata = <LOG>;

 ...

>     mikej>  foreach $line (@indata)

 ...

> my( @indata ) = <DEMO>;

 ...

> foreach ( @indata )  {

 ...

> Not that I don't believe you,  

Why not?  I didn't believe him for one second.

Of course, both you and he try to read entire files into arrays instead 
of processing them one line at a time, so I don't see why I should 
believe you, either.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 30 Sep 1999 22:09:43 GMT
From: albuck@my-deja.com
Subject: help with simple interactivity
Message-Id: <7t0n2v$nn5$1@nnrp1.deja.com>



I have a system script for bulk labeling of storage
volumes in a robotic library.  These scripts are
written in ksh, and they build another small ksh
script on the fly which is a here document of the
following form:

labelvol-command arg1 arg2 ... argn <<EOF
VOLSER1
VOLSER2
VOLSER3

EOF

(The labelvol command exits when it receives a blank line.)

I am trying to move my scripts to perl.  Obviously, I can still
build this ksh here document script and run it, but somehow
that seems to defeat the purpose of using perl.  How can I
build and execute the same here document without involving
the shell?  I know, TMTOWTDI.  :-)  Multiple solutions gladly
accepted by this eager student.

Also, this is the blind input solution, since I am not
checking for errors being returned by the labelvol utility.
How would I go about driving the input of this program line
by line, and capturing the output line by line?  I could
show some of my attempts but they fail so miserably, I would
rather not.

Thanks alot!

Lester
--
A. Lester Buck     buck@compact.LEAVETHISOFF.com


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


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

Date: Thu, 30 Sep 1999 22:24:27 GMT
From: alex_rayan@my-deja.com
Subject: Help with this Crazy script!
Message-Id: <7t0nue$o8e$1@nnrp1.deja.com>

Hi friends,
   Can anybody help me with the following script? Its not printing 2
verfied messages!!!

my $y ="z";

if ($y =~ /z/gi){
   print "\nVerified 1";
}

if ($y =~/a|z/gi){
   print "\nVerified 2 ";
}

print "\n End";




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


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

Date: Thu, 30 Sep 1999 15:10:56 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: HTML to ASCII
Message-Id: <37F3DFF0.D669556F@mail.cor.epa.gov>

Jonathan Stowe wrote:
> 
> In comp.lang.perl.misc David Cassell <cassell@mail.cor.epa.gov> wrote:
[snip about Abigail]
> > Oh, so now you'll be writing with a German accent and we'll
> > have to pronounce your name as "Ahh-bi-gail".  Hmmph.
> >
> > Or maybe not.  Wasn't the T-1000 programmed in COBOL?
> > No wonder he lost to a couple humans.
> 
> So what you say - Johnny 5 was programmed in Perl, ED-209 in Ada,
> HAL-9000 in Perl, WOPPA in Prolog, K-9 in Python, ORAC in Perl,
> The Daleks and the Cybermen probably in COBOL, Holly and Kryten in
> Perl, Klaatu - APL ?

Not quite.  I mean that the T-1000 had to *literally* be
running COBOL, because in the first Terminator movie you can
see COBOL code scrolling through his view as he tracks
someone.  

Talk about bad help from the comp-sci community...

Are we far enough off-topic yet?

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: 30 Sep 1999 17:19:49 -0500
From: Art Haas <arthur.haas@westgeo.com>
Subject: Re: numeric sort on field 2 in @array...
Message-Id: <lrn1u411q2.fsf@yoda.wg.waii.com>

<shiloh@shell9.ba.best.com> writes:

> I could not find this "exactly" in perfunc or perlfaq4.
> I want to do a numeric sort only on field 2 of an @array.
> 
> Here is the data file:
> cat junk11
> fred 2
> wilma 3 
> larry 5
> tom 4
> barney 1
> betty 1
> 
> Here is what I want to do in perl:
> sort -rn +1 junk11
> larry 5
> tom 4
> wilma 3 
> fred 2
> betty 1
> barney 1
> 
> [ ... script snipped with error message ... ]
>

This looks like a job for ... the Schwartzian Transformation!!!

(I'm guessing your input file is still called 'junk11')

#!/usr/local/bin/perl

use strict;

open(DATA,"./junk11") || die "Can't open data! $!\n";
my @sorted =
	map { $_->[0] }
	sort { $b->[2] <=> $a->[2] or $b->[1] cmp $a->[1] }
	map { [ $_ , (split) ] } <DATA>;
close(DATA);

foreach (@sorted) {
	print;
}

Running this gives me ...

% perl sortscript.pl
larry 5
tom 4
wilma 3
betty 1
barney 1
%

Just what you were looking for ..

If you want similar names alphabetized, change the sort line above to

	sort { $b->[2] <=> $a->[2] or $a->[1] cmp $b->[1] }

then, 'barney' appears before 'betty' ...

-- 
###############################
# Art Haas
# (713) 689-2417
###############################


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

Date: Thu, 30 Sep 1999 15:28:39 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: numeric sort on field 2 in @array...
Message-Id: <MPG.125d83f593aea04298a00f@nntp.hpl.hp.com>

In article <37F3DBD0.9431901B@sni.net> on Thu, 30 Sep 1999 15:53:20 -
0600, Dr. John Griffiths <grifftoe@sni.net> says...
> rather than using built-in sort I write the array to a file,
> pass it to bin/sort, and read it back in - its fast and
> easy.

Good strategy.

I suggest that Perl is bloated with unnecessary builtin functions.  
Let's get rid of:

chmod
chown
grep
kill
link
localtime
mkdir
rename
rmdir
sleep
symlink
umask
unlink
utime
 ...

It's 'fast and easy' to do all of these things using system() or qx() or 
whatever.

After all, Perl is a 'glue language', isn't it?  Who cares if all the 
things glued together might not be portable.  We can always construct a 
portable environment using POSIX tools or ppt or whatever.

I'm so sorry Uri Guttman and I wasted so much effort on analyzing the 
Perl sort() function, when all we had to do all along was to 'pass it to 
bin/sort'.

HAND.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 30 Sep 1999 22:37:26 GMT
From: <shiloh@shell9.ba.best.com>
Subject: Re: numeric sort on field 2 in @array...
Message-Id: <37f3e626$0$217@nntp1.ba.best.com>

Larry Rosler <lr@hpl.hp.com> wrote:
: [Posted and a courtesy copy mailed.]

: You say you want to sort on only one field, not on several.  The 
: relevant example is the one right ahead of this in the FAQ.  If you have 
: trouble making that work, come back with the code that failed, and 
: someone will help you.

OK - right out of the FAQ with minor modifications to fit the data.

Here is the script:
cat junk78.pl
#!/usr/local/bin/perl5
 
open(INFILE,"junk11") || die "cannot open junk11 $!";
@array = <INFILE>;
 
@sorted = ();
 
@sorted = map  { $_->[0] }
          sort { $a->[1] <=> $b->[1] }
          map  { [ $_, uc((/\d+\s*(\S+)/ )[0] ] } @array;
 
print "================== \n";
 
foreach $item (@sorted){
  chomp($item); 
  print "$item \n";
}


I assume the [1] is the second field in the sort.  That's what
I want to sort by.  I changed the "cmp" to "<=>".

Here is what I get:

 ./junk78.pl
syntax error at ./junk78.pl line 10, near "] ]"
Execution of ./junk78.pl aborted due to compilation errors.

The [] look like they match, so what's wrong?

thanks,


--Joe McCaughan   | The blessing of the Lord makes one rich,
shiloh@best.com   | And He adds no sorrow with it.            Proverbs 10:22





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

Date: Thu, 30 Sep 1999 17:26:47 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: numeric sort on field 2 in @array...
Message-Id: <37F3E3A7.E970A7FC@texas.net>

"Dr. John Griffiths" wrote:
> 
> rather than using built-in sort I write the array to a file,
> pass it to bin/sort, and read it back in - its fast and
> easy.

You have the strangest notion of 'fast and easy' upon which I have ever
stumbled...

To quote Abigail, et. al.:

*boggle*

- Tom


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

Date: 30 Sep 1999 18:55:55 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: numeric sort on field 2 in @array...
Message-Id: <x7g0zwuhz8.fsf@home.sysarch.com>

>>>>> "S" ==   <shiloh@shell9.ba.best.com> writes:

  S> @array = <INFILE>;

no need for that.
 
  S> @sorted = ();
 
nor that.

  S>           map  { [ $_, uc((/\d+\s*(\S+)/ )[0] ] } @array;
                                               ^^^
  S> syntax error at ./junk78.pl line 10, near "] ]"

  S> The [] look like they match, so what's wrong?

no close ) for uc.

i think you want something like this:

	map  { [ $_, uc( (/\d+\s*(\S+)/)[0] ) ] } @array;

use a better editor that balances parens.

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 15:59:58 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: numeric sort on field 2 in @array...
Message-Id: <37F3EB6E.465E17D5@mail.cor.epa.gov>

Dr. John Griffiths wrote:
> 
> rather than using built-in sort I write the array to a file,
> pass it to bin/sort, and read it back in - its fast and
> easy.

If I may say...  Ick.  You write to a file, open a shell and
run another program, then read a file back in?  Seems a lot
harder than sort(), and a *lot* slower.  I guess it won't make
any difference with a small file.  But some people here
regularly manipulate files more than a Gig in size.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Thu, 30 Sep 1999 15:55:21 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: numeric sort on field 2 in @array...
Message-Id: <MPG.125d8a372e2a171798a011@nntp.hpl.hp.com>

In article <lrn1u411q2.fsf@yoda.wg.waii.com> on 30 Sep 1999 17:19:49 -
0500, Art Haas <arthur.haas@westgeo.com> says...
> <shiloh@shell9.ba.best.com> writes:
> > I want to do a numeric sort only on field 2 of an @array.

 ...

> This looks like a job for ... the Schwartzian Transformation!!!

Oh, no.  You are wasting your time.  Dr. John Griffiths has explained 
that the true solution is to use 'bin/sort' (sic)!

 ...

> my @sorted =
> 	map { $_->[0] }
> 	sort { $b->[2] <=> $a->[2] or $b->[1] cmp $a->[1] }
> 	map { [ $_ , (split) ] } <DATA>;

That does more than requested, because it also sorts on field 1.  One 
might simply sort only on field 2 as requested:

  	sort { $b->[1] <=> $a->[1] }
  	map { [ $_ , (split)[1] ] } <DATA>;

or

  	sort { $b->[1] <=> $a->[1] }
  	map { [ $_ , /(\d+)$/ ] } <DATA>;

> foreach (@sorted) {
> 	print;
> }

  print @sorted;

 ...

> If you want similar names alphabetized, change the sort line above to
> 
> 	sort { $b->[2] <=> $a->[2] or $a->[1] cmp $b->[1] }
> 
> then, 'barney' appears before 'betty' ...

They are also alphabetized in your original code (above), just in 
reverse order.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 30 Sep 1999 22:59:46 GMT
From: <shiloh@shell9.ba.best.com>
Subject: Re: numeric sort on field 2 in @array...
Message-Id: <37f3eb62$0$217@nntp1.ba.best.com>

Art Haas <arthur.haas@westgeo.com> wrote:
: <shiloh@shell9.ba.best.com> writes:

: This looks like a job for ... the Schwartzian Transformation!!!

: open(DATA,"./junk11") || die "Can't open data! $!\n";
: my @sorted =
: 	map { $_->[0] }
: 	sort { $b->[2] <=> $a->[2] or $b->[1] cmp $a->[1] }
: 	map { [ $_ , (split) ] } <DATA>;
: close(DATA);

This little code snip worked for me.  It is much more
intuitive and compiles (sic) too.

  # Sort the @sort_array numerically on the second field (priority).
  # This routine was retrieved from the newsgroup: comp.lang.perl.misc
  # on 990930.
  #
  my @sorted =
        map { $_->[0] }
        sort { $b->[2] <=> $a->[2] or $b->[1] cmp $a->[1] }
        map { [ $_ , (split) ] } @sort_array;
 
  @sort_array = @sorted;

You can easily understand where field 2 is and add more fields 
if necessary.  I will add this to my perlnotes file :)

thanks a lot folks!

--Joe McCaughan   | The blessing of the Lord makes one rich,
shiloh@best.com   | And He adds no sorrow with it.            Proverbs 10:22



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

Date: Thu, 30 Sep 1999 15:32:52 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Perl AI Apps/Expert Systems
Message-Id: <37F3E514.7AE9CADD@mail.cor.epa.gov>

none wrote:
> 
> Does anyone know if there are any Perl developed AI Apps out there, Expert
> systems, etc?

If you go to deja.com and search this newsgroup's archive, you
will find that this was discussed a month or three ago.  I
believe a mailing list solely for Perl & AI was mentioned,
with a subscriber address.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Thu, 30 Sep 1999 17:08:45 -0500
From: Seth David Johnson <sjohns17@uic.edu>
Subject: Re: RegEx for html->plain text
Message-Id: <Pine.A41.4.10.9909301705410.242516-100000@tigger.cc.uic.edu>

On Thu, 30 Sep 1999, Sushant Gargya wrote:

> Looking for "parser" that would take an html input file and
> output the file without the html tags encountered. In other words,
> need a converter that converts html file to plain text file.

Not to be down on Perl, but is there any reason you're not simply using 
lynx with the -dump option?

Otherwise, you might want to take a look at HTML::Parser. Using RegExs for
this is painful (though I've heard less so with the next Perl release).

-Seth



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

Date: 30 Sep 1999 22:07:09 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Suggestion - comp.lang.perl.flame (was Re: You should be admired)
Message-Id: <7t0mud$8de@dfw-ixnews5.ix.netcom.com>

Kai Henningsen (kaih=7Pq08Bpmw-B@khms.westfalen.de) wrote:
: abigail@delanet.com (Abigail)  wrote on 29.09.99 in <slrn7v3a6l.a6f.abigail@alexandra.delanet.com>:
: > And? Just because newbies can't find the obvious group, a new group in
: > the wrong hierarchie should be created? That's stupid.
: 
: Well yes, the world often *is* stupid. You hadn't noticed?
: 
: Don't think of it as accommodating the idiots. Think of it as a fly trap.

But experience shows that what will happen is that if a new CGI-Perl 
group is created, the script kiddies will simply crosspost into it rather 
than using it exclusively.  Look at all the Web server-configuration 
questions that wind up in comp.lang.perl.tk.  The clueless will just 
crosspost into everything that has "perl" in its name.



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

Date: Thu, 30 Sep 1999 15:31:33 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Thread.pm
Message-Id: <37F3E4C5.9B5A8096@mail.cor.epa.gov>

nraghuram@my-deja.com wrote:
> 
> is there any site from where Thread.pm can be downloaded.
> what is the optimal way to communicate from a child to the parent in a
> multi-child scenario. i tried using a combination of pipes and hash
> arrays and have the parent poll before creation of the next child to
> check if earlier children  have returned data. but it seems to be taking
> too long.

[1] If you want threads, you have to compile Perl to use
threads.  But then your Perl will take a performance hit on
anything that is non-threaded.

[2] If you want to communicate between a parent and children,
read the perlipc section, and take a look at the code in The
Perl Cookbook too.  Often the problem is the algorithms used,
or mistakes in coding the IPC, rather than what is assumed.

[3] I can't give you any more help than that, since you have
not shown any code [like, say, 20 lines which illustrate your
point] and hence I have no way of knowing if you coded your
program well.. or not.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Thu, 30 Sep 1999 22:19:39 GMT
From: j_v_schmitt@my-deja.com
Subject: Upload problem w/ Apache/Linux/CGI.pm
Message-Id: <7t0nlf$o5d$1@nnrp1.deja.com>

Hi,
Very strange to me... I hope not to you:
My simple form handler dies ("Premature end of script headers" shows
up in the log file) when I DON'T specify a file to upload.

If I do specify a file to upload, then the form handler passes by fine,
and will display "Hello there".

I'm running Apache 1.3.6 on Redhat Linux 6.0, and have installed CGI.pm
This worked fine on my Unix/Netscape server, but fails on the
Linux/apache.

Here's the bare-bones handler file:

#!/usr/bin/perl

# creates new CGI object using the CGI.pm library
       use CGI qw(:standard);
  $query = new CGI;

print header;
print "<html>";
print "<head><title>Nothin</title></head><body bgcolor=#FFDDFF>";
print "Hello there";
print "</body></html>";

Any suggestions which may stop my 6 hour debuggin headache?
John


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


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

Date: Thu, 30 Sep 1999 15:45:23 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Using SS Numbers as DBM Index: Best Way to Encrypt Them
Message-Id: <37F3E803.E1D546F@mail.cor.epa.gov>

George Kuetemeyer wrote:
> 
> I need to create several DBM files based on feeds from various campus
> systems. I want to use social security numbers as indices, but would
> like to encrypt them for the sake of privacy. Since I want to use the

George, you have gotten some good answers from the tech side.
But you might want to run this concept by TJU's legal staff.
There have been some issues lately with using SSNs as identifiers,
and I don't know if encrypting them will get you out of Lawsuit
Land.  Good luck.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Thu, 30 Sep 1999 21:57:50 GMT
From: geotekjohn@my-deja.com
Subject: Wrong value returned when accessing list using scalar variable?
Message-Id: <7t0mcn$n9b$1@nnrp1.deja.com>

I'm trying to get the value of a particular item in a list using a
straightforward $mylist[$myindex] syntax. I have 2 lists set up (to
simulate rows and columns in a table), and given a cell number, I try
to figure out the row and column for that cell, and then print the
value for that cell.

But I sometimes get the wrong value when I use a scalar variable as an
index to one of the lists. Here's the code:


#!/usr/bin/perl -w
use strict;
use diagnostics;

=pod

I'm trying to convert a cell number (1 .. n, where n is the # of cells
in the table) to a 0-based row and column index.

=cut

my @row_values=qw(row0 row1);
my @col_values=qw(col0 col1 col2);
$\ = "\n";

for (my $cell_number = 1; $cell_number <= 6; $cell_number++)
{
	#temp variables and and b help clean up some of the code below
	my $a = $cell_number - 1;
	my $b = @col_values;

	#The row index is a div b
	my $row_index = int($a / $b);
	my $col_index;

	#	$col_index = a mod b  Since there is no MOD function in
perl, I implemented one myself.
	if (($a/$b) < 1)
	{
		$col_index = $a;
	}
	else
	{
	#	print "a = $a \t b = $b";
		$col_index = abs((int ($a/$b) - ($a/$b)) * $b);
	}

	print "Row index = $row_index \t Col index = $col_index ";
	print "&RowValue=" . $row_values
[$row_index] . "&ColumnValue=" . $col_values[$col_index];
	print "";

=pod

This works as expected
		for (my $col_i = 0; $col_i < @col_values; $col_i++)
		{
			print "Col index = $col_i \t Column value =
$col_values[$col_i]";
		}
		#This is also OK
		print "Hardcoded: RowValue0 = $row_values[0] ColValue1
= $col_values[1] ";

=cut

}
exit (0);



Here's the output:

Row index = 0    Col index = 0
&RowValue=row0&ColumnValue=col0

Row index = 0    Col index = 1
&RowValue=row0&ColumnValue=col1  <--- Works here just fine

Row index = 0    Col index = 2
&RowValue=row0&ColumnValue=col2

Row index = 1    Col index = 0
&RowValue=row1&ColumnValue=col0

Row index = 1    Col index = 1
&RowValue=row1&ColumnValue=col0  <--- Why is this col0 ?? Should be col1

Row index = 1    Col index = 2
&RowValue=row1&ColumnValue=col2

I using  perl, version 5.005_03 built for MSWin32-x86-object
(ActiveState 520 version). Could I possibly be doing something wrong?

TIA,
John


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


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

Date: Thu, 30 Sep 1999 15:33:06 -0700
From: menolly <menolly@spy.net>
Subject: Re: You should be admired
Message-Id: <2107d358.5a282636@usw-ex0107-052.remarq.com>

I'm a female coder. I do both C/C++ and Perl. I prefer
Perl, currently.  I don't post here much for a couple of
reasons:

1) This is a very active newsgroup; I don't have time to
really keep up with it -- most questions have been answered
before I see them, and I rarely have questions so obscure I
can't find the answer in the docs.

2) I'm not that good.  I want to be; I'm reading and coding
as much as I can to improve my skills, but I'm just not
there yet.  I learned a lot at TPC this year. But I don't
get to use Perl _that_ much in my current job, so it's hard
to apply the knowledge.  I'm currently focusing on Perl/Tk,
since I have a formerly-command-line script which was
running out of rememberable flags, and will benefit greatly
from a GUI interface.

As for why there aren't more of us, that's a good question.
One I'm afraid I don't have a good answer for.

--cathy
(For those who may be wondering, I'm the woman who was
wearing a green hat with a black feather in it throughout
the conference.)


* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



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

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


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