[17565] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4985 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 29 03:05:40 2000

Date: Wed, 29 Nov 2000 00:05:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <975485111-v9-i4985@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 29 Nov 2000     Volume: 9 Number: 4985

Today's topics:
        affiliate program script in perl? (Loans2001)
    Re: AOL email --> RFC822, stuck. <taboo@comcen.com.au>
    Re: AOL email --> RFC822, stuck. <taboo@comcen.com.au>
    Re: Can anyone help me with this script??? <mjcarman@home.com>
        Dynaloading broken.  On Solaris 8?!!! (Ilya Zakharevich)
        Embedding a VBA script into Excel from Perl ezhik_273@my-deja.com
    Re: Encrypting passwords <rereidy@indra.com>
        FAQ 4.2:   Why isn't my octal data interpreted correctl <faq@denver.pm.org>
    Re: flypages <mjcarman@home.com>
    Re: How do I query a named to translate IP into hostnam <carvdawg@patriot.net>
    Re: How do I query a named to translate IP into hostnam (Martien Verbruggen)
    Re: How do I query a named to translate IP into hostnam <bcaligari@my-deja.com>
    Re: How do I query a named to translate IP into hostnam <taboo@comcen.com.au>
    Re: How do I query a named to translate IP into hostnam (Andrew N. McGuire)
    Re: How to get directory name where script is located a <rereidy@indra.com>
    Re: Manipulating File Modification Time (Tad McClellan)
        memory errors using fork on NT? <cak@xxx.putzl.com>
    Re: Most easy way to get IP from a local NIC by device  (Ilya Zakharevich)
    Re: PLEASE HELP ME???!!!! (Ilya Zakharevich)
        Problems writing file using Perl on NT (IIS 4 + Perl 5. <eweb.support@esolutions.co.nz>
    Re: Problems writing file using Perl on NT (IIS 4 + Per <philipg@atl.mediaone.net>
        proxy autoconfig brett_wilson@my-deja.com
    Re: Recursively load all objects in an HTML page... (Eric Bohlman)
    Re: Regex question about \x$1 theredviper@my-deja.com
    Re: Regex question about \x$1 (Eric Bohlman)
    Re: running Perl program on NT and accessing a UNIX mac <rereidy@indra.com>
    Re: Simple Open file fails in Active Perl 5.6.0 on Wind <uri@sysarch.com>
    Re: system() argument: multiple spaces collapsed into s <jeffo@mninter.net>
    Re: system() argument: multiple spaces collapsed into s <bcaligari@my-deja.com>
        Unsort array in Perl??? <hal@exch.com>
    Re: Unsort array in Perl??? <joe+usenet@sunstarsys.com>
    Re: Unsort array in Perl??? <hal@exch.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 29 Nov 2000 06:33:55 GMT
From: loans2001@aol.com (Loans2001)
Subject: affiliate program script in perl?
Message-Id: <20001129013355.06006.00002253@ng-ck1.aol.com>

Does anyone know where I can find a perl script that does an affiliate program
for my website?  Running on Unix server.  Looking for free script.

Scot King


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

Date: 29 Nov 2000 14:12:27 +1100
From: "Kiel Stirling" <taboo@comcen.com.au>
Subject: Re: AOL email --> RFC822, stuck.
Message-Id: <3a24741b$1@nexus.comcen.com.au>


gjs.REMOVE@khalsa.com wrote:
>(sorry if this posted twice -- server weirdness)>
>
>Hi All,
>
>I am trying to create a script with that will convert AOL email
>messages to a standard RFC format, and it is not working the way I
>expect.  If you don't know, AOL puts the headers beneath the body of
>the email, thusly:
>
>
>#BODY
>#BODY
>#BODY
>#BODY
>#BODY
>--------------------Headers --------------------
>#HEADERS
>#HEADERS
>#HEADERS
>#HEADERS
why not read the file in  with a while loop?

use strict;
my @header;
open EMAIL, "PATH TO EMAIL FILE" or die $!;
while (<EMAIL>) {
	my $headers = 1 if /--------------------Headers --------------------/;
	next unless $headers;
	my ($before,$after); 
	($before,$after) = split ":", $_ ;
	$header{$before} = $after;
}
close EMAIL;


this is not tested script.

Regards,

Kiel Stirling



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

Date: 29 Nov 2000 14:16:59 +1100
From: "Kiel Stirling" <taboo@comcen.com.au>
Subject: Re: AOL email --> RFC822, stuck.
Message-Id: <3a24752b$1@nexus.comcen.com.au>


"Kiel Stirling" <taboo@comcen.com.au> wrote:
>>gjs.REMOVE@khalsa.com wrote:
>>(sorry if this posted twice -- server weirdness)>
>>
>>Hi All,
>>
>>I am trying to create a script with that will convert AOL email
>>messages to a standard RFC format, and it is not working the way I
>>expect.  If you don't know, AOL puts the headers beneath the body of
>>the email, thusly:
>>
>>
>>#BODY
>>#BODY
>>#BODY
>>#BODY
>>#BODY
>>--------------------Headers --------------------
>>#HEADERS
>>#HEADERS
>>#HEADERS
>>#HEADERS
>why not read the file in  with a while loop?
>
>use strict;
>my %header;
>open EMAIL, "PATH TO EMAIL FILE" or die $!;
>while (<EMAIL>) {
>	my $headers = 1 if /--------------------Headers --------------------/;
>	next unless $headers;
>	my ($before,$after); 
>	($before,$after) = split ":", $_ ;
>	$header{$before} = $after;
>}
>close EMAIL;
>
>
>this is not tested script.
>
>Regards,
>
>Kiel Stirling
>
Last post had a typo @header should be %header


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

Date: Tue, 28 Nov 2000 10:25:29 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: Can anyone help me with this script???
Message-Id: <3A23DC79.AC879DA5@home.com>

Ross wrote:
> 
> What I'm trying to create is a program that will use the /etc/dict 
> (or other wordfile) and pick random words from this file and insert
> them into a textfile, replacing each instance of 'ZZZZ' with one of
> these random words.
> Finally, when the string 'ZZZX' is encountered, a random word is 
> used to replace this value and the new file is saved under a unique
> name.  The process then starts again using the original file with 
> all the ZZZZ values etc, creating a number of these output 
> documents all with unique names.
>
> What I've created so far is a (semi-buggy) file copying program.
[...]
> I just can't quite get it to do what I want (grrrrr....).

What part is giving you problems? The replacement? Creating the output
file names? Reading the input file?

Here's some *UNTESTED* code which handles the replacement portion, with
just enough stuff wrapped around it to make it functional. You'll want
to modify it to fit into what you already have, but it should point you
in the right direction.

Note: I don't know what the format of /etc/dict is, I've assumed one
word per line. You may want to change the implementation of the
Replacement() sub if the wordfile is large and you don't want to keep
the whole thing in memory. What I've shown here is just a basic example.

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

my $infile   = 'template.txt';
my $outfile  = 'blarg.txt';
my $dictfile = '/etc/dict';

open(REPL, $dictfile) or die "Can't open '$dictfile' [$!]\n";
my @replword = <REPL>;
chomp(@replword);
close(REPL);

open(IN, $infile) or die "Can't open '$infile' [$!]\n";
open(OUT, ">$outfile") or die "Can't open '$outfile' [$!]\n";

while(<IN>) {
    s/ZZZ[XZ]/Replacement()/eg;
    print OUT $_;
    last if (/ZZZX/);
}

close(IN);
close(OUT);

sub Replacement {
    return($replword[rand(@replword)]);
}

-mjc


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

Date: 29 Nov 2000 03:37:01 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Dynaloading broken.  On Solaris 8?!!!
Message-Id: <901tkt$3ms$1@charm.magnus.acs.ohio-state.edu>

It is a Solaris 8 machine, and the only platform-specific problem I
had with Perl during the last two years was that the general
architecture of DynaLoading on Solaris is somehow broken (see the
thread about Term::ReadLine::Gnu problems with a custom malloc() -
which it should not have).

But today I got a problem which looks absolutely elementary:

 ->make test
 PERL_DL_NONLAZY=1 /opt/local/bin/perl -Iblib/arch -Iblib/lib	\
	-I/opt/local/lib/perl5/5.00503/sun4-solaris		\
	-I/opt/local/lib/perl5/5.00503 test.pl
 Can't load 'blib/arch/auto/OpenGL/OpenGL.so' for module OpenGL:
   ld.so.1: /opt/local/bin/perl: fatal: relocation error:
     file blib/arch/auto/OpenGL/OpenGL.so:
	symbol sv_unglob: referenced symbol not found
	  at /opt/local/lib/perl5/5.00503/sun4-solaris/DynaLoader.pm line 169.

[Wrapped for clarity].

 ->nm /opt/local/bin/perl | grep unglob
 [221]   |    497236|     160|FUNC |LOCL |0    |9      |sv_unglob

So what now?  Do I need to reboot ;-), or what?

Ilya

P.S.  This is a test of OpenGL 0.53-tobe, so do not try to reproduce
      it today. ;-)


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

Date: Wed, 29 Nov 2000 04:12:58 GMT
From: ezhik_273@my-deja.com
Subject: Embedding a VBA script into Excel from Perl
Message-Id: <901vo6$2pc$1@nnrp1.deja.com>

Hi, everybody,
I'm processing some data to put them into a
formatted Excel sheet, and I need to add some
controls, i.e., check boxes. I know how to create
these controls in Perl and how to define their
functions in Visual Basic, but I have no idea how
I could add a VBA module with procedure
definitions to an Excel document (all from a Perl
script).
If someone could throw in an idea or give a
reference, help would be appreciated

Thanks

Sasha


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


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

Date: Tue, 28 Nov 2000 21:47:56 -0700
From: Ron Reidy <rereidy@indra.com>
Subject: Re: Encrypting passwords
Message-Id: <3A248A7C.DF135774@indra.com>

Rob Greenbank wrote:
> 
> OK, I've searched Deja News and haven't seen anyone with an acceptable
> solution to my problem.  I have a number of perl scripts that connect
> to databases (Oracle).  That connection requires a password, and
> obviously we would prefer to not store that password in clear text.
> 
> The obvious solution is to encrypt the password somehow.  If I'm using
> perl, however, the information on how to decrypt the password is
> stored in human readable form.  I don't see this as much of an
> improvement.  The only solution I've come up with so far, less than
> perfect, is a compiled program (C, for instance) that decrypts the
> encrypted passwords.  This program verifies the parent was the perl
> script it was designed to service (not perfect security, but better
> than nothing).  Source code does not contain the password (passed on
> the compilation command line).
> 
> This problem has to exist for others, especially using the BDI
> modules.  Has anyone else come up with a better way to solve this?
> 
> Thanks,
> 
>         Rob
>         (rob@frii.com)
I have used OPS$ accounts (when not needing to connect to a remote DB). 
I have also seen these stored in a file with is crypt'ed (not my idea of
security).

Actually your best bet is:

1.  Use DB Roles and Profiles, and create users who have these roles and
profiles assigned to them.  
2.  Disable the schema owner's accounts (so no one can log in as them).
3.  Change SYS and SYSTEM passwords.
4.  Remove DBA and DBOPER privs from any "application" schema accounts.
5.  Look at fine-grained security for tighter security.
6.  Define your business processes and use stored procedures (either
Java or PL/SQL) to implement thos processes (especially INSERT, UPDATE,
DELETE).

Good luck.
-- 

Ron Reidy
Oracle DBA
Reidy Consulting, L.L.C.


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

Date: Wed, 29 Nov 2000 04:17:01 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ 4.2:   Why isn't my octal data interpreted correctly?
Message-Id: <1r%U5.157$QX6.171058176@news.frii.net>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.

+
  Why isn't my octal data interpreted correctly?

    Perl only understands octal and hex numbers as such when they occur as
    literals in your program. If they are read in from somewhere and
    assigned, no automatic conversion takes place. You must explicitly use
    oct() or hex() if you want the values converted. oct() interprets both
    hex ("0x350") numbers and octal ones ("0350" or even without the leading
    "0", like "377"), while hex() only converts hexadecimal ones, with or
    without a leading "0x", like "0x255", "3A", "ff", or "deadbeef".

    This problem shows up most often when people try using chmod(), mkdir(),
    umask(), or sysopen(), which all want permissions in octal.

        chmod(644,  $file); # WRONG -- perl -w catches this
        chmod(0644, $file); # right

- 

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep comming up.  If you are some how irritated by
seeing these postings you are free to ignore them or add the sender
to your killfile.  If you find errors or other problems with these
postings please send corrections or comments to the posting email
address.

If you are not able to find this or other Perl documentation from
your installation you may access it via the web by following the
appropriate links from one of the addresses listed below.

    http://theoryx5.uwinnipeg.ca/mod_perl/cpan-search
    http://www.perldoc.com
    http://www.cpan.org
    http://www.perl.com

Answers to questions about LOTS of other stuff, mostly not related to
Perl, can be found at

    news:news.answers

and in the many thousands of other useful Usenet news groups.

The perlfaq manual pages contain the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-1999 Tom Christiansen and Nathan
    Torkington.  All rights reserved.

    When included as an integrated part of the Standard
    Distribution of Perl or of its documentation (printed or
    otherwise), this work is covered under Perl's Artistic
    License.  For separate distributions of all or part of
    this FAQ outside of that, see the perlfaq manpage.

    Irrespective of its distribution, all code examples here
    are public domain.  You are permitted and encouraged to
    use this code and any derivatives thereof in your own
    programs for fun or for profit as you see fit.  A simple
    comment in the code giving credit to the FAQ would be
    courteous but is not required.

-- 
    This space intentionally left blank


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

Date: Tue, 28 Nov 2000 10:35:13 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: flypages
Message-Id: <3A23DEC1.8AC31DB8@home.com>

Chuck Williams wrote:
> 
> There's a site out there www.flypage.com selling a Perl-based HTML
> page construction 'wizard'. My client purchased it. I've gotta go in
> and fix what someone else left behind.
> If you have experience with their product, I'd appreciate even a word
> or two of advice. (I already saw one posting warning people against
> it.)

So, what's the deal? Are you supposed to implement the use of this
product on your client's site? Fix the product where it's broken? Repair
damage the product caused? If it's either of the first two, I'd say that
you should take it up with the company providing the product. (After
all, that's what they get paid for.)

-mjc


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

Date: Tue, 28 Nov 2000 21:15:22 -0500
From: H C <carvdawg@patriot.net>
Subject: Re: How do I query a named to translate IP into hostname
Message-Id: <3A2466BA.6276A3AB@patriot.net>


--------------A96F4E2412ACDC6BEE687D4E
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

> I have a script that checks to see what stations are up, but I would
> like if a stations is up to get its CNAME/realname/ IP address into a
> name address.
>

#! c:\perl\bin\perl.exe

############################################################
# name.pl
# Runs on Linux, NT, Win9x
# Use Socket functions to lookup IP addresses and hostnames
# Ex: perl name.pl <host or IP>
#
# H. Carvey 1999, 2000
############################################################

use strict;
use Socket;

my $target = shift || die "Must provide a hostname or IP address\n";

my($ip);

$ip = inet_ntoa(inet_aton($target));
print "Target:\t\t$target\n";
print "IP:\t\t$ip\n";
my ($name,$alias,$addrtype,$length,$new_addr) =
   gethostbyaddr(inet_aton($ip),AF_INET) || die "Could not find host:
$!\n";
print "Hostname:\t$name\n";# if ($name ne $target);
print "Alias:\t$alias\n" if ($alias ne "");




--
Q: Why is Batman better than Bill Gates?
A: Batman was able to beat the Penguin.


--------------A96F4E2412ACDC6BEE687D4E
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>

<blockquote TYPE=CITE>I have a script that checks to see what stations
are up, but I would
<br>like if a stations is up to get its CNAME/realname/ IP address into
a
<br>name address.
<br><a href="http://www.hinwick.demon.co.uk"></a>&nbsp;</blockquote>
#! c:\perl\bin\perl.exe
<p>############################################################
<br># name.pl
<br># Runs on Linux, NT, Win9x
<br># Use Socket functions to lookup IP addresses and hostnames
<br># Ex: perl name.pl &lt;host or IP>
<br>#
<br># H. Carvey 1999, 2000
<br>############################################################
<p>use strict;
<br>use Socket;
<p>my $target = shift || die "Must provide a hostname or IP address\n";
<p>my($ip);
<p>$ip = inet_ntoa(inet_aton($target));
<br>print "Target:\t\t$target\n";
<br>print "IP:\t\t$ip\n";
<br>my ($name,$alias,$addrtype,$length,$new_addr) =
<br>&nbsp;&nbsp; gethostbyaddr(inet_aton($ip),AF_INET) || die "Could not
find host:&nbsp; $!\n";
<br>print "Hostname:\t$name\n";# if ($name ne $target);
<br>print "Alias:\t$alias\n" if ($alias ne "");
<br>&nbsp;
<br>&nbsp;
<br>&nbsp;
<p>--
<br>Q: Why is Batman better than Bill Gates?
<br>A: Batman was able to beat the Penguin.
<br>&nbsp;</html>

--------------A96F4E2412ACDC6BEE687D4E--



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

Date: Wed, 29 Nov 2000 02:09:04 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: How do I query a named to translate IP into hostname
Message-Id: <slrn928p6f.br5.mgjv@verbruggen.comdyn.com.au>

On Wed, 29 Nov 2000 01:16:11 +0000,
	Mark Worsdall <linux@wizdom.org.uk> wrote:
> Hi,
> 
> I have a script that checks to see what stations are up, but I would
> like if a stations is up to get its CNAME/realname/ IP address into a
> name address.

You mean a workstation?

Check the perlfunc documentation, and look for the gethost* functions.
Also check the documentation for the Socket module.

To get full DNS information, you may want to have a look at Net::DNS,
available from your local CPAN archive or http://www.cpan.org/.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | For heaven's sake, don't TRY to be
Commercial Dynamics Pty. Ltd.   | cynical. It's perfectly easy to be
NSW, Australia                  | cynical.


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

Date: Wed, 29 Nov 2000 02:16:15 GMT
From: Brendon Caligari <bcaligari@my-deja.com>
Subject: Re: How do I query a named to translate IP into hostname
Message-Id: <901ota$t9d$1@nnrp1.deja.com>

In article <ulZ292CbjFJ6Ewv9@worsdall.demon.co.uk>,
  Mark Worsdall <linux@wizdom.org.uk> wrote:
> Hi,
>
> I have a script that checks to see what stations are up, but I would
> like if a stations is up to get its CNAME/realname/ IP address into a
> name address.
>
> Any modules to do this?
>
> M.

backtickign `nslookup ip` returns hostname (plus some other stuff that
can be regexed out)

B


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


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

Date: 29 Nov 2000 13:57:41 +1100
From: "Kiel" <taboo@comcen.com.au>
Subject: Re: How do I query a named to translate IP into hostname
Message-Id: <3a2470a5$1@nexus.comcen.com.au>


Brendon Caligari <bcaligari@my-deja.com> wrote:
>In article <ulZ292CbjFJ6Ewv9@worsdall.demon.co.uk>,>  Mark Worsdall <linux@wizdom.org.uk> wrote:
>> Hi,
>>
>> I have a script that checks to see what stations are up, but I would
>> like if a stations is up to get its CNAME/realname/ IP address into a
>> name address.
>>
>> Any modules to do this?
>>
>> M.
>
>backtickign `nslookup ip` returns hostname (plus some other stuff that
>can be regexed out)
>
not platform independent use Socket 



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

Date: 28 Nov 2000 22:31:34 -0600
From: anmcguire@ce.mediaone.net (Andrew N. McGuire)
Subject: Re: How do I query a named to translate IP into hostname
Message-Id: <87itp7wg9l.fsf@hawk.ce.mediaone.net>

>>>>> "BC" == Brendon Caligari <bcaligari@my-deja.com> writes:

BC> In article <ulZ292CbjFJ6Ewv9@worsdall.demon.co.uk>,
BC>   Mark Worsdall <linux@wizdom.org.uk> wrote:
>> Hi,
>> 
>> I have a script that checks to see what stations are up, but I would
>> like if a stations is up to get its CNAME/realname/ IP address into a
>> name address.
>> 
>> Any modules to do this?

BC> backtickign `nslookup ip` returns hostname (plus some other stuff that
BC> can be regexed out)

No need for that:

#!/usr/bin/perl -w
use strict;
use Socket; # no need for this, but is more succinct than unpack()

my ($name,$aliases,$addrtype,$length,@addrs)
   = gethostbyname('www.coastalnet.com');

@addrs = map inet_ntoa($_), @addrs;

print <<EOF;
  name     -> $name
  aliases  -> $aliases
  addrtype -> $addrtype
  length   -> $length
  addrs    -> @addrs
EOF

Modifying that to go the other way around is trivial.

anm

-- 
perl -wMstrict -e '
$a=[[qw[J u s t]],[qw[A n o t h e r]],[qw[P e r l]],[qw[H a c k e r]]];$.++
;$@=$#$a;$$=[reverse sort map$#$_=>@$a]->[$|];for$](--$...$$){for$}($|..$@)
{$$[$]][$}]=$a->[$}][$]]}}$,=$";$\=$/;print map defined()?$_:$,,@$_ for @$;
'


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

Date: Tue, 28 Nov 2000 21:49:28 -0700
From: Ron Reidy <rereidy@indra.com>
Subject: Re: How to get directory name where script is located and is run from?
Message-Id: <3A248AD8.AC6C2F0@indra.com>

dnshtern@my-deja.com wrote:
> 
> I am using Perl under Win98. Environment
> variable, %ENV, does not contain the information.
> Could anyone help me with the problem?
> 
> Thanks,
> DS
> 
> Sent via Deja.com http://www.deja.com/
> Before you buy.
Look at FindBin and Cwd.
-- 

Ron Reidy
Oracle DBA
Reidy Consulting, L.L.C.


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

Date: Tue, 28 Nov 2000 20:09:11 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Manipulating File Modification Time
Message-Id: <slrn928lpn.1o7.tadmc@magna.metronet.com>

J Garcia <garcia868@yahoo.com> wrote:

>Is it possible to modify file modification times with
>Perl and is there some neat trick that I have
>overlooked? 


Errr, is a function for doing that a neat trick?

   perldoc -f utime

:-)


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Tue, 28 Nov 2000 18:46:39 -0800
From: Chris Kantarjiev <cak@xxx.putzl.com>
Subject: memory errors using fork on NT?
Message-Id: <3A246E0F.6FF9D78A@xxx.putzl.com>

I'm using fork under NT for the first time; the goal is to do some
really quick and dirty load testing of a web server. I've put this all
together mostly from Cookbook examples.

It works, but ... more often than not, especially as I bump the number
of threads up to about 30 or more, I get a popup that says

"The instruction at "0x..." referenced memory at "0x...". The memory
could not be "read". 

There's typically about n-5 such dialog boxes, where n is the number of
children forked.

I've been looking for screwups in my code, but don't immediately see
any. Of course, that doesn't mean that they aren't there ... but maybe
this is a known problem in NT?

Thanks,
chris

use CGI qw(:standard);		# Must be used to get the param() function
use POSIX "sys_wait_h";
use LWP::Simple;
use sigtrap qw(die normal-signals);

sub dprint {
#    print @_;
}

sub sendMessages($$$) {
    my ($threadNo, $nMesgs, $url) = @_;
    for (my $i = 0; $i < $nMesgs; $i++) {
	my $now = time();
	my $nowstr = localtime($now);
	my $content;
	my $URL = $url."&msginv=perl thread $threadNo msg $i $nowstr";
	if (!defined($content = get ($URL))) {
	    warn "thread $threadNo / $i could not get $url \n";
	    sleep 1;		# give server a chance to recover
	} else {
	    print "$threadNo: $i: $nowstr took ", time() - $now,
	          " seconds: $content\n";
	}
    }
}

if (scalar(@ARGV) != 3) {
    die "usage: $0 <nThreads> <msgsPerThread> <URL>";
}
($nThreads, $nMesgs, $url) = @ARGV;

$startTime = time();

$nowstr = localtime(time());
print "$nowstr : start timing loop, submitting ",
    $nThreads*$nMesgs," messages from $nThreads threads\n";

for ($i = 0; $i < $nThreads ; $i++) {
  FORK:
    if ($pid = fork) {
	# parent here
	$childIDs[$i] = $pid;
	dprint "forked $i -> $pid \n";
    } elsif (defined $pid) { # $pid is zero here if defined
	# child here
	sendMessages($i, $nMesgs, $url);
	exit;
    } elsif ($! =~ /No more process/) {
	# EAGAIN, supposedly recoverable fork error
	sleep 1;
	print "redoing FORK\n";
	redo FORK;
    } else {
	# weird fork error
	die "Can't fork: $!\n";
    }
}

foreach $child (@childIDs) {
    dprint "waiting for $child \n";
    waitpid ($child, 0);
}

$now = time();
$delta = $now - $startTime;
printf "Submitted %d msgs in %d seconds, avg %g/sec\n",
    $nThreads * $nMesgs, $delta, $i/$delta;

--
		      Remove xxx. to reply ...


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

Date: 29 Nov 2000 05:26:45 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Most easy way to get IP from a local NIC by device name (eth0,eth1...)
Message-Id: <90242l$5qe$1@charm.magnus.acs.ohio-state.edu>

[A complimentary Cc of this posting was NOT sent to Martien Verbruggen
<mgjv@tradingpost.com.au>],
who wrote in article <slrn91m9h5.r2.mgjv@verbruggen.comdyn.com.au>:
> > What is bad with netstat -i or -I?  Is it not portable?  Or does it
> > not work with eth0?
> 
> the options to netstat are highly unportable, as is the output. On
> linux netstat -i doesn't give you any addresses, and -I doesn't exist.
> On Solaris -i gives you the addresses (as does -I, but limited to the
> specified interface).

I see.  On os2 I need -r and -a.  But ifconfig works (after half an
hour ong tries to find which option I need to give it to get a report,
I found that both on Solaris and OS/2 you need to give no
options. ;=()

Ilya


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

Date: 29 Nov 2000 02:40:54 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: PLEASE HELP ME???!!!!
Message-Id: <901qbm$2ms$1@charm.magnus.acs.ohio-state.edu>

[A complimentary Cc of this posting was NOT sent to Joe Schaefer 
<joe+usenet@sunstarsys.com>],
who wrote in article <m3ofyz7iwd.fsf@mumonkan.sunstarsys.com>:

> @words = ('a'..'e');
> @rows = (0,1,2,3,4);
> $_ = "This ZZZZ ZZZZ ZZZZ is clever ZZZZ\n";
> s/ZZZZ/$words[pop @rows]/g;
> 
> print ; # prints "This e e e is clever e"

> That can't be the intended behavior, can it?

Definitely not.

Ilya


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

Date: Wed, 29 Nov 2000 17:42:22 +1300
From: "Dave K" <eweb.support@esolutions.co.nz>
Subject: Problems writing file using Perl on NT (IIS 4 + Perl 5.0)
Message-Id: <QN%U5.421$Fn.15138934@news.xtra.co.nz>

Hi there,
I am attempting to troubleshoot a script written by a customer of mine. It
is basically a small storefront app that takes orders, then processes them
(no cc authentication - just writes orders to a filename).

Currently we have it setup to write to the ./orders/ directory within the
cgi-bin directory (ie. ~/cgi-bin/orders/). The problem we are having is that
orders just do not get written to the directory. The error generated is
File Error
 Unable to open ./U738843983
where U738843983 is just any random number assigned to an order. The
relevant subroutines in the perl are:

#---------------------------------------------------------
# Subroutine to write the data to a file.
#---------------------------------------------------------
sub write_data
{
   # Local variables associated with arguments.
   local ($file_name, $order_data) = @_;
   $file_name =~ s/[\.\;\|\/]//g;
   $order_data =~ s/[\.\;\|\/]//g;

   # Open file for writing.
   if (open(FILE, ">" . $order_directory . $file_name))
   {
      # Write the data to the file.
      print FILE $order_data;

      # Close the file.
      close(FILE);
   }
   else
   {
      # Indicate that the file was not opened.
      &return_error("File Error","Unable to open " . $order_directory .
$file_name);
   }
}
# End of write_data()

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

#---------------------------------------------------------
# Subroutine to read a file.
#---------------------------------------------------------
sub read_file
{
   # Reference to arguments passed to this subroutine.
   local (*FILEDATA,$file_name,$options) = @_;
   $order_directory =~ s/[\.\;\|\/]//g;
   $file_name =~ s/[\.\;\|\/]//g;

   # Other variables used in this subroutine.
   local ( $line, $payment_lines );

   # Open file for reading.
   open (FILE, $order_directory . $file_name) ||
      &return_error("File Error","Unable to read " . $order_directory .
$file_name);

   # Reset number of payment lines left.
   $payment_lines = 0;

   # Initialize $FILEDATA.
   $FILEDATA = "";

   # Read entire file line by line.
   while (<FILE>)
   {
      # Set $line equal to the last line read from file.
      $line = $_;

      # Check if payment info should be included in email.
      if ($options eq "NO")
      {
         # Check if this line contains payment information.
         if ($line =~ /PAYMENT INFORMATION/)
         {
            # There are four lines that contain payment info.
            $payment_lines = 4;
         }
         elsif ($line =~ /CHECKING INFORMATION/)
         {
            # There are eight lines that contain payment info.
            $payment_lines = 8;
         }
         elsif ($payment_lines > 0)
         {
            # Decrement payment lines left.
            $payment_lines--;
         }
         else
         {
            # This line is not a payment line, add it to messagebody.
            $FILEDATA = $FILEDATA . $line;
         }
      }
      else
      {
         # Concatenate all lines onto messagebody.
         $FILEDATA = $FILEDATA . $line;
      }
   }

   # Close file.
   close(FILE);
}
# End of read_file()


From what I can tell, everything should work as desired...but it doesn't! I
have doublechecked the relevant NTFS permissions and all are set properly.
Can anybody notice any inherent problems we may have with the above code?
The script is designed to be UNIX / NT portable and if anyone wants to
replicate the error, simply go to www.agooddealmore.co.nz and order
something. Choose COD and just fill out garbage data once you get to the
payment page.
Any help would be *most* appreciated!
Thanks,
David (esolutions NZ)




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

Date: Wed, 29 Nov 2000 05:27:26 GMT
From: "Philip Garrett" <philipg@atl.mediaone.net>
Subject: Re: Problems writing file using Perl on NT (IIS 4 + Perl 5.0)
Message-Id: <2t0V5.828$88.210971@typhoon.southeast.rr.com>

Dave K <eweb.support@esolutions.co.nz> wrote in message
news:QN%U5.421$Fn.15138934@news.xtra.co.nz...
> Hi there,
> I am attempting to troubleshoot a script written by a customer of mine. It
> is basically a small storefront app that takes orders, then processes them
> (no cc authentication - just writes orders to a filename).
>
> Currently we have it setup to write to the ./orders/ directory within the
> cgi-bin directory (ie. ~/cgi-bin/orders/). The problem we are having is
that
> orders just do not get written to the directory. The error generated is
> File Error
>  Unable to open ./U738843983
> where U738843983 is just any random number assigned to an order. The
> relevant subroutines in the perl are:

Use the $! variable to get more information out of Perl.  See below.

> #---------------------------------------------------------
> # Subroutine to write the data to a file.
> #---------------------------------------------------------
> sub write_data
> {
>    # Local variables associated with arguments.
>    local ($file_name, $order_data) = @_;
>    $file_name =~ s/[\.\;\|\/]//g;
>    $order_data =~ s/[\.\;\|\/]//g;
>
>    # Open file for writing.
>    if (open(FILE, ">" . $order_directory . $file_name))
>    {
>       # Write the data to the file.
>       print FILE $order_data;
>
>       # Close the file.
>       close(FILE);
>    }
>    else
>    {
>       # Indicate that the file was not opened.
>       &return_error("File Error","Unable to open " . $order_directory .
> $file_name);

Change that line to:
    &return_error("File Error", "Unable to open
${order_directory}${file_name}: $!");
That should help you troubleshoot the problem.

BTW, the & isn't really needed.

[snip]

hth,
p




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

Date: Wed, 29 Nov 2000 05:47:43 GMT
From: brett_wilson@my-deja.com
Subject: proxy autoconfig
Message-Id: <90259v$6mo$1@nnrp1.deja.com>

Hi All,

I have a quick question.
I have a cgi script that is for two proxy servers where it looks at
one , if that server is down it jumps to the next server. see below

PROXY w3proxy.netscape.com:8080; PROXY mozilla.netscape.com:8081

What is the connection that is made to see if the first server is up?

Thanks in Advance

Brett


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


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

Date: 29 Nov 2000 06:47:26 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Recursively load all objects in an HTML page...
Message-Id: <9028pu$jj6$2@bob.news.rcn.net>

snakedjip@yahoo.com wrote:
> A browser (like IE or Netscape) would then start downloading all of the
> elements of that web page.  For example, if a web page contains "<IMG
> SRC=...>" tags, or "<SCRIPT SRC=...>" tags, the browser would download
> the contents of those files, and embed them in the final document.  Of
> course, if any of these "sub-documents" contains other "SRC=" tags, the
> browser will load them recursively...

> I want to reproduce this behaviour in Perl.

> The first solution that comes to mind is to parse the document
> for "SRC=<document>", and load the contents of this <document> with
> another LWP call, and do that recursively...

That had better be the first solution that comes to mind, as it's the only
solution that fits the problem description.

> Is there an easier way ?

No.

> What packages do you suggest I use ?

HTML::LinkExtor.  It will take care of the parsing for you and give you a
list of the URLs that you need to deal with.



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

Date: Wed, 29 Nov 2000 06:15:28 GMT
From: theredviper@my-deja.com
Subject: Re: Regex question about \x$1
Message-Id: <9026tt$7u5$1@nnrp1.deja.com>

I would like thank everyone for the comments and suggestions; they are
all appreciated.  This was part of a project that was neither work
related nor classroom related, but only one for the sake of learning
more about perl and regular expressions.

I just have a few comments about the last post.  I hope I don't step on
anyone's toes, I just want to clarify a few points.

Please excuse my quoting style, I'll work more on it next weekend. :)



In article <slrn9209bh.3oc.tadmc@magna.metronet.com>,
  tadmc@metronet.com (Tad McClellan) wrote:
> Martin Heinsdorf <martinheinsdorf@codesign.net> wrote:
>
> >You're on the right track.
>
> No he isn't, nor are you.
>
> The "right track" is using a library to decode URLs, where all
> of the tiny details have already been worked out, and the
> solution has been examined by many people.
>

The "right track" would certainly depend on my goals or destination
which you were unaware of, so you don't have enough information to say
that I'm on the wrong track.  I normally would have used something like
CGI.pm to do this task but I decided against it with this project.  I'm
certainly not an advocate of reinventing the wheel, but I've found it to
be one of the best ways to learn about programming.




> Working it out yourself, with input from random Usenauts,
> is a waste of time. You might miss something. Vanishingly
> few people have reviewed the code.
>

maybe


> Doing this as anything other than simply a learning exercise
> where you will not be using the code in "real" programs
> is the Wrong Track.
>

right on.


> Your "solution" isn't good enough yet either.
>
> (But experienced lurkers would have already distrusted your
>  advice due to cues given by your quoting style.
>
>  Whether Jeopardy quoting really correlates to lower-quality
>  content does not matter. What matters is the perception
>  of the newsgroup readers. And that perception hereabouts
>  is well established.
>
>  Don't reverse time if you don't want to be discounted.
> )

Is discrediting someone elses comment the only way people will accept
yours?


>
> >Just one more step to go...
> >
> >$myvar =~ s/%(..)/chr hex($1)/eg;
>
> >> $myvar = "he says %27if it works use it%27";
>
> Try it with this:
>
>    my $myvar = "he says %  if it works use it%%%";
>
> It deletes data characters that are not URL encoded.
>
> Discarding data is most often a Bad Thing.
>

True. The above string would cause problems, but I'm only working with
URL encoded data.  Of course I can already hear an argument about code
reuse brewing, but as someone else already pointed out there is a better
way to create the regex that would fix the above problem.



> >> while ($myvar =~ m/%(..)/){
> >>         $my_temp = chr hex($1);
> >>         $myvar =~ s/%../$my_temp/;
>
> [ snip a bunch of Jeopardy quoted text with _multiple_ time
>   discontinuities.
> ]
>
> --
>     Tad McClellan                          SGML consulting
>     tadmc@metronet.com                     Perl programming
>     Fort Worth, Texas
>



With all of your comments Tad the only usuable information that I could
find is a theme about being cautious of whose advice you take.  Thanks.
Point taken.  ;)


Thanks again to everyone for all the comments.  This group is a great
place to learn about programming perl and sadly about bad attitudes.


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


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

Date: 29 Nov 2000 07:25:11 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Regex question about \x$1
Message-Id: <902b0n$jj6$3@bob.news.rcn.net>

theredviper@my-deja.com wrote:
> Please excuse my quoting style, I'll work more on it next weekend. :)

The quoting style you're currently using is just fine.  It's
conversational, as is the style of discourse in this newsgroup.

> The "right track" would certainly depend on my goals or destination
> which you were unaware of, so you don't have enough information to say
> that I'm on the wrong track.  I normally would have used something like
> CGI.pm to do this task but I decided against it with this project.  I'm
> certainly not an advocate of reinventing the wheel, but I've found it to
> be one of the best ways to learn about programming.

Not if the wheel in question is full of nitpicking details.  Just about
anything to do with CGI *is* full of nitpicking details.  It's easy to get
lost in them.  At any stage in one's learning of programming, the best
problems to pick are the ones that, by stretching a little, you can solve
*completely* rather than producing a half-assed job of a solution.  Doing
the latter means that you're stretching beyond your current reach, and you
really don't learn as much when you do that.

> Thanks again to everyone for all the comments.  This group is a great
> place to learn about programming perl and sadly about bad attitudes.

Your statement about bad attitudes is true, but probably not in the way
you intended.



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

Date: Tue, 28 Nov 2000 21:37:13 -0700
From: Ron Reidy <rereidy@indra.com>
Subject: Re: running Perl program on NT and accessing a UNIX machine
Message-Id: <3A2487F9.EC0D1FE4@indra.com>

Lex Hagen wrote:
> 
> Subj.: running Perl program on NT and accessing a UNIX machine
> 
> Hi,
> 
> Is it possible to run a Perl program on a Windows NT machine, that logs
> on
> to a remote UNIX machine? On that machine the Perl program should
> execute some
> commands and when this is finished, it should disconnect from the UNIX
> machine and execute some commannds on the Win NT machine (from where it
> is running). After that the Perl program can be terminated.
> 
> Anybody knows whether this is possible and how?
> 
> All tips are welcome, please send a copy of your respons to
> L.Hagen@HumanInference.nl
> 
> Thanks in advance,
> 
> Lex
You might try looking at Net::Rexec or running the remote command with
an ssh pipe.
-- 

Ron Reidy
Oracle DBA
Reidy Consulting, L.L.C.


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

Date: Wed, 29 Nov 2000 04:32:27 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Simple Open file fails in Active Perl 5.6.0 on Windows2000 Advanced Server + IIS 5.0
Message-Id: <x7bsuzbdpf.fsf@home.sysarch.com>


use IO::Socket ;

no need to get dirty with low level socket code.

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: Tue, 28 Nov 2000 22:02:45 -0600
From: "Jeffrey R. Olson" <jeffo@mninter.net>
Subject: Re: system() argument: multiple spaces collapsed into single space
Message-Id: <901v5d0dmk@enews3.newsguy.com>

"Brendon Caligari" <bcaligari@my-deja.com> wrote in message
news:901kfk$pph$1@nnrp1.deja.com...
>
> run system with a list as parameter, and it should work fine
>
> system('myprog', 'param1', "'hello  world'", 'param3');
>
> Brendon
>

Brendan, that doesn't work.  If I change the system call in test1.pl to:

system('perl', 'test2.pl', "'$infile'");

Then I get as output:

$infile in test1.pl: hello  world
$infile in test2.pl: 'hello

I'm curious if you got the same result when you tested it.  You did test it,
right? :-)

Any other ideas, anyone?

- Jeff




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

Date: Wed, 29 Nov 2000 07:45:05 GMT
From: Brendon Caligari <bcaligari@my-deja.com>
Subject: Re: system() argument: multiple spaces collapsed into single space
Message-Id: <902c61$bfc$1@nnrp1.deja.com>

In article <901v5d0dmk@enews3.newsguy.com>,
  "Jeffrey R. Olson" <jeffo@mninter.net> wrote:
> "Brendon Caligari" <bcaligari@my-deja.com> wrote in message
> news:901kfk$pph$1@nnrp1.deja.com...
> >
> > run system with a list as parameter, and it should work fine
> >
> > system('myprog', 'param1', "'hello  world'", 'param3');
> >
> > Brendon
> >
>
> Brendan, that doesn't work.  If I change the system call in test1.pl
to:
>
> system('perl', 'test2.pl', "'$infile'");
>
> Then I get as output:
>
> $infile in test1.pl: hello  world
> $infile in test2.pl: 'hello
>
> I'm curious if you got the same result when you tested it.  You did
test it,
> right? :-)

actually yes.  and I wrote the equivalent code in C, but the latter's
system didn't bollock things up :)

With the first example you posted I got your same results.  However,
feeding system a list of scalars (quoted in ''s) preserves spaces.  I
am using ActivePerl Build 620.

Brendon




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


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

Date: Wed, 29 Nov 2000 00:41:43 -0500
From: halid <hal@exch.com>
Subject: Unsort array in Perl???
Message-Id: <3A249717.7479EB06@exch.com>

Hi everybody!
I have a weird question. I have an array that has elements in not any
particular order. I need to unsort elements further at random....
Any ideas??
Help would be greately appreciated.
I know there are ways to do it by converting it to hash and then call
keys out of it but it doesn't work too good and too bulky.
I am looking for a simple way to do it.
Thanks!
Mark.

If you could, please reply by e-mail: http://getfree.org/gotmail/?design





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

Date: 29 Nov 2000 00:35:38 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Unsort array in Perl???
Message-Id: <m3elzv732t.fsf@mumonkan.sunstarsys.com>

halid <hal@exch.com> writes:

> Hi everybody!
> I have a weird question. I have an array that has elements in not any
> particular order. I need to unsort elements further at random....
> Any ideas??

% perldoc -q shuffle


-- 
Joe Schaefer


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

Date: Wed, 29 Nov 2000 02:17:28 -0500
From: halid <hal@exch.com>
Subject: Re: Unsort array in Perl???
Message-Id: <3A24AD88.43EA469D@exch.com>

Thanks Joe!
Mark.


Joe Schaefer wrote:

> > Hi everybody!
> > I have a weird question. I have an array that has elements in not any
> > particular order. I need to unsort elements further at random....
> > Any ideas??
>
> % perldoc -q shuffle
>
> --
> Joe Schaefer



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

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


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