[7022] in Perl-Users-Digest
Perl-Users Digest, Issue: 647 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 23 20:07:17 1997
Date: Mon, 23 Jun 97 17:00:30 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 23 Jun 1997 Volume: 8 Number: 647
Today's topics:
Re: "odd number of elements" warning with {} <esupu@warwick.ac.uk>
* FREE SOFTWARE * (Steve Johnson)
Re: ***How to get info from the HTML files in other ser <jens-and@NO.dsv.su.se.SPAM>
Re: a perl mode in emacs that does a better job with qu <vladimir@cs.ualberta.ca>
Re: CGI and the system() call <rootbeer@teleport.com>
CGI:downloading .exe with Perl sann0474@sable.ox.ac.uk
Re: CGI:downloading .exe with Perl (Lloyd Zusman)
Re: delayed Output <rootbeer@teleport.com>
Exception package? <rpang@us.oracle.com>
Re: Generating random numbers fast (Andrew M. Langmead)
Re: get end of string (easy question) <wesley@woais.com>
Hash question. <cmason@ti.com>
Re: Hash question. (Andrew M. Langmead)
Re: Llama question <esupu@warwick.ac.uk>
Making a MUD with CGI darkmanlives@hotmail.com
Re: microsoft personal web server parsing perl scripts (Parillo)
OOP - class variables and inheritance? (felix k sheng)
Passing object references to a subroutines (Toutatis)
Re: Perl SIGINT Handling <c.evans@clear.net.nz>
Re: PERL to Oracle (Bob Wilkinson)
Re: print "Hi", last ... <esupu@warwick.ac.uk>
Re: reading a data file? (Andrew M. Langmead)
regular expressions (Tri Tram)
Re: safely opening a file while under assumed UID/GID <rootbeer@teleport.com>
Re: socket under solaris <johnmoore@pdsi-software.com>
stdin, stdout, exec <cgweav@eskimo.com>
Use Perl in C <howard.yen@mci2000.com>
what is my, lc and etc and where to learn it? <esupu@warwick.ac.uk>
Re: When do I call srand? <rootbeer@teleport.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 21 Jun 1997 20:41:15 +0100
From: mike mah <esupu@warwick.ac.uk>
To: Brian Wheeler <bdwheele@indiana.edu>
Subject: Re: "odd number of elements" warning with {}
Message-Id: <Pine.SOL.3.95.970621203921.1075A-100000@crocus>
On 19 Jun 1997, Brian Wheeler wrote:
> Date: 19 Jun 1997 19:00:05 GMT
> From: Brian Wheeler <bdwheele@indiana.edu>
> Newsgroups: comp.lang.perl.misc
> Subject: Re: "odd number of elements" warning with {}
>
> In article <33A1B44E.17FE@nss.harris.com>,
> Alan Sparks <asparks@nss.harris.com> writes:
> >I've the following line in a script:
> >
> > %foo = {};
> >
> >Perl (5.004) complains:
> >
> > Odd number of elements...
> >
> >I don't think that's so odd... Besides, zero is even. So says my
> >math teacher anyway.
> >
> >Why does this assignment deserve this warning? Or it there a more
> >appropriate way to initialize a hash?
> >
> >Thanks in advance... I'd prefer any comments to e-mail, but will take
> >what I can get... :-)
>
>
> It odd, though. You're assigning the hash foo to a _hash reference_,
> which is a single item, therefore odd. If you want to assign an empty hash,
> just use %foo=().
>
>
> Brian
>
> >
> >-Alan
> >-------------------------------
> >Alan Sparks, IS Engineering Support asparks@harris.com
> >Harris Network Support Systems, Camarillo CA 93012 (805) 389-2430
>
> --
> Brian Wheeler
> bdwheele@indiana.edu
>
>
There is no reason why you need to initialise associative array.
you can use it right away when you need without initialise it first.
Hope it helps.
Let's strike for exellent.
Yours sincerely,
mike mah
------------------------------
Date: Mon, 23 Jun 97 11:47:17 GMT
From: steve@mail-mtt.com (Steve Johnson)
Subject: * FREE SOFTWARE *
Message-Id: <335f6471.0@news.pbcs.com>
Keywords: Free, Free, Free, Free, Software, Software, Software, Software, Windows, File, Disk, Utilities, Business, Finance, Graphics, PIMs, Screen, Savers
VERY IMPORTANT INFORMATION
Surf Over Our SEA Of Software !
1) What is SoftSEA Programs Center ?
It is the most comprehensive Distribution Web Site
for Windows Shareware & Freeware Software Programs
The center is divided into 30 software areas,
Windows Utilities, File & Disk Utilities, Business
Finance, Graphics, PIMs, Screen Savers, and many
others! These areas contain only the newest & coolest
programs available. They can be downloaded for FREE
by FTP, HTTP, or sent to you by E-mail.
There is even a service by which you can discuss with
all the users of the program you use. If you have
uncertainties about the program, this is the place
where your questions will get answered!
Every area has its own mailing list so you can
receive a weekly message with the latest programs
which have been added to that area.
2) Where is SoftSEA Programs Center ?
It is located on the World Wide Web at:
http://www.softsea.com
3) In the end ...
Hoping that you will download as many programs as
you wish from the center, we kindly thank you, and
we are waiting for you to surf over our sea of
software at http://www.softsea.com
Sincerely,
Steve Johnson
------------------------------
Date: Sun, 22 Jun 1997 15:26:43 +0200
From: Jens M Andreasen <jens-and@NO.dsv.su.se.SPAM>
Subject: Re: ***How to get info from the HTML files in other server??***
Message-Id: <Pine.OSF.3.95.970622151200.10109A-100000@tellus.dsv.su.se>
On Fri, 20 Jun 1997, Johnny wrote:
:Hi,
: Is there any ways to get information from a HTML files located in
:other server (different from the one you are on)?? I want to be able to
:grep info from HTML files in other server and use it in my own HTML
:file. If you have any clue, please help me out.
:The language used doesn't really matter, as long as it can achieve the
:task.
You can use:
lynx -dump http://www.somewhere/path/file.html | grep whatever
This will give a text only output. If you want to keep the formatting use:
lynx -source etc etc
(
)
c[] // Jens M Andreasen
------------------------------
Date: 22 Jun 1997 16:25:59 -0600
From: Vladimir Alexiev <vladimir@cs.ualberta.ca>
Subject: Re: a perl mode in emacs that does a better job with quotes?
Message-Id: <omen9ugtqg.fsf@tees.cs.ualberta.ca>
In article <wriuz9vhp4.fsf@esrin.esa.it> Simon Marshall <Simon.Marshall@esrin.esa.it> writes:
> Ilya added the low-level support for per-character syntax to Emacs
Ahh, the wonders of technology. This reminds me of a paper that I think every
aspiring OOP-er should read:
author={B. Stavtrup},
title={A Proposal Regarding Invisible Logic For Object-Oriented Languages},
journal={Journal of Object-Oriented Programming}, volume=5, number=1,
year=1992, pages={63-65},
annote={The author makes a proposal to the ANSI C++ Committee for an
extension of the operator-overloading facilities of C++ so that whitespace
can also be used for this purpose.}
With per-char syntax, one can go even further! Now we can overload the space
following the ` on the next line to mean "cout", and the dot after it to mean
operator<<, so ` ."blorf"' would mean "print" pretty much like Forth.
And the space-dot on thes line would mean "read": ` .foo'. Now every
programmer can create their own argot! We don't need to stinkin PGP!
."yep"
PS: in case you don't get it, abbreviate the article title.
------------------------------
Date: Sat, 21 Jun 1997 13:50:54 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Castellan <douglas@mailhost.ecn.uoknor.edu>
Subject: Re: CGI and the system() call
Message-Id: <Pine.GSO.3.96.970621134907.24220E-100000@kelly.teleport.com>
On 18 Jun 1997, Castellan wrote:
> Newsgroups: comp.lang.perl
If your news administrator still carries comp.lang.perl, please encourage
him or her to check out the frequent posting about bogus newsgroup names
in news.announce.newgroups. You'll be doing yourself and many others a
favor to use comp.lang.perl.misc (and other valid Perl newsgroups)
instead.
news:news.announce.newgroups
> Subject: CGI and the system() call
Perl doesn't know or care that you're writing a CGI script, and
consequently neither do we. :-)
> I want to execute the following command:
>
> system 'touch file.dat';
Why? More precisely, why don't you do this directly from perl with the
utime operator?
> from CGI, but it fails to create the file "file.dat" as
> specified. I can execute the script from the command line and have it
> create the file, no prob. Is this an issue dealing with the write permissions
> set under the web server,
Sounds like it.
When you're having trouble with a CGI program in Perl, you should first
look at the please-don't-be-offended-by-the-name Idiot's Guide to
solving such problems. It's available on the perl.com web pages. Hope
this helps!
http://www.perl.com/perl/
http://www.perl.com/perl/faq/
http://www.perl.com/perl/faq/idiots-guide.html
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Sun, 22 Jun 1997 08:51:55 -0600
From: sann0474@sable.ox.ac.uk
To: sann0474@sable.ox.ac.uk
Subject: CGI:downloading .exe with Perl
Message-Id: <866986846.21795@dejanews.com>
Hi-
>From discussions in this newsgroup and other sources I have some code (see
below) to allow a user to download an .exe file from an HTML page. On
small-ish files (<1.5meg) this works just fine. However, as the since of
file to be downloaded gets larger, it seems to take longer and longer
before the browser actually begins to download until files > 1.5 meg just
seems to hang. Note that while I can't quite figure out what the server
is doing, it is doing something based on it's light and memory usage.
If I reference the file with a standard HREF (rather than using CGI),
there is no problem downloading (I've tried up to 8 meg).
I'm using CGI and Perl to do some password checking, log entries and to
force the filename.
Any ideas what is going wrong?
Thanks
Lydia
sann0474@sable.ox.ac.uk
[PERL code]
if (open (THEFILE, "$filepath")) {
local($/) = undef;
$attribute = -s $filepath;
print "Content-Length: $attribute\n";
print "Content-Disposition: inline;filename=\"$in{'file'}\"\n";
print "Content-Type: application/octet-stream\n\n";
binmode (THEFILE);
binmode (STDOUT);
select (STDOUT);
$| = 1;
print <THEFILE>;
close (THEFILE);
} else {
Location:....[some page with message]
}
[end code]
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: 22 Jun 1997 15:13:52 GMT
From: asfast@asfast.com (Lloyd Zusman)
Subject: Re: CGI:downloading .exe with Perl
Message-Id: <slrn5qqg4v.b0j.asfast@ljz.asfast.net>
On Sun, 22 Jun 1997 08:51:55 -0600, sann0474@sable.ox.ac.uk <sann0474@sable.ox.ac.uk> wrote:
> Hi-
>
> From discussions in this newsgroup and other sources I have some code (see
> below) to allow a user to download an .exe file from an HTML page. On
> small-ish files (<1.5meg) this works just fine. However, as the since of
> file to be downloaded gets larger, it seems to take longer and longer
> before the browser actually begins to download until files > 1.5 meg just
> seems to hang. Note that while I can't quite figure out what the server
> is doing, it is doing something based on it's light and memory usage.
>
> [ ... ]
>
> [PERL code]
>
> if (open (THEFILE, "$filepath")) {
> local($/) = undef;
> $attribute = -s $filepath;
> print "Content-Length: $attribute\n";
> print "Content-Disposition: inline;filename=\"$in{'file'}\"\n";
> print "Content-Type: application/octet-stream\n\n";
> binmode (THEFILE);
> binmode (STDOUT);
> select (STDOUT);
> $| = 1;
> print <THEFILE>;
^^^^^^^^^^^^^^^^
> close (THEFILE);
> } else {
> Location:....[some page with message]
> }
>
> [end code]
The statement I marked (above) reads the entire file into an array before
it starts printing. For large files, this has two side effects:
(1) It may take a long time (on a slow machine) for the entire file to
get read in before printing.
(2) You may run out of virtual memory before the file can get read in
completely, thereby causing your CGI to crash before it can send
anything back to you.
A solution would be for you to replace that line with the following loop:
while (defined($line = <THEFILE>)) {
print $line;
}
This will read and print your file one line at a time, thereby bypassing
the above-mentioned problems.
You might also want to try this (where 8192 is a buffer size ... you
can choose a more appropriate size for your system):
while (sysread(THEFILE, $buffer, 8192) > 0) {
print $buffer;
}
And finally, if you move your "$| = 1" command before your first
'print' statement (before the statement printing "Content-Length"),
you might be able to do it this way:
while (($length = sysread(THEFILE, $buffer, 8192)) > 0) {
syswrite(STDOUT, $buffer, $length);
}
I hope this helps.
--
Lloyd Zusman
ljz@asfast.com
------------------------------
Date: Sat, 21 Jun 1997 13:57:24 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: J|rgen Mangler <a4431ndm@pcserv.univie.ac.at>
Subject: Re: delayed Output
Message-Id: <Pine.GSO.3.96.970621135532.24220G-100000@kelly.teleport.com>
On 19 Jun 1997, J=FCrgen Mangler wrote:
> I want to create a cgi-programm that prints characters (e.g. 10) into
> the browser window with a delay of 1 second. But the browser always
> waits until the whole document is created (for example 10 seconds for
> these 10 characters) and then he loads in the whole page in one peace.
> Is there a way to reach this 'slowly-reading-the-characters-in' effect?=
=20
Yes, but you need to know that this is not a Perl question. It's a CGI
question. Having said that, I'll tell you that what you're trying to do
(which may not work with all browsers) is explained in the CGI
specifications where it discusses "nph" scripts. Good luck!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Mon, 23 Jun 1997 14:15:29 -0700
From: "Robert Pang" <rpang@us.oracle.com>
Subject: Exception package?
Message-Id: <5omp5i$2dk$1@inet16.us.oracle.com>
Hi everyone,
I am looking for an exception management (C++ throw-and-catch stuff)
package for Perl. I came across a package called Experimental::Exception
by Torsten Ekedahl. In his README file, he mentions that there is
currently a discussion on a built-in exception mechanism in Perl. Does
anyone know the details?
Thanks.
Rober Pang
rpang@us.oracle.com
Oracle Corp.
------------------------------
Date: Mon, 23 Jun 1997 21:05:35 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Generating random numbers fast
Message-Id: <EC8yLB.GrL@world.std.com>
Aveek Datta <MoNoLiTH+@CMU.EDU> writes:
>I want to find a quick way to generate decent random numbers fast.
>The srand specified in the Perl book seems to call ps -auwx and gzip to get
>the random seed. Won't this be relatively slow on CGI's which get dozens of
>hits per sec?
>Hence I'd like a fast way to get a random number. The number itself isnt too
>important, I'm using it to implement a 'percentage chance' thing where let's
>say I want 50% chance that something happens.
You're not complaining about calculating random numbers to be slow,
just initializing the random number generator. Some ideas might be:
1. Have each CGI task write its random number to a file, use that as
the seed of the next iteration. (Would this maintain a equal
distribution of random numbers? Maybe I should check Jon Orwant's
article on common random number generators to double check.)
2. Make a daemon process that listens to a unix domain socket or a
fifo. Have it spit a random number at any connection it
receives. Since this daemon will only have call srand once, your seed
calculation can be as complex as you want it to be.
3. Use a simpler seed ignore the fact that a cryptographic analysis
might be able to determine your next random number. It doesn't seem
like you need "statistically random", just "unlikely to be guessed by
the user". The time alone may be a good enough seed. Actually, with
network delays, whether the result of localtime is even or odd may be
a good enough random number to determine a 50% chance.
>I'm running on Linux systems and I know /dev/random might be useful. How can
>I use that in Perl? Of course if there is a non-Linux specific way that
>would be useful too.
I would guess that "/dev/random" is a system wide random number
generator with a seed determined at startup. In practice, it would
probably work as well my "random number daemon" idea.
--
Andrew Langmead
------------------------------
Date: Sun, 22 Jun 1997 23:45:41 -0500
From: Wesley Miaw <wesley@woais.com>
Subject: Re: get end of string (easy question)
Message-Id: <33ADFF75.6F6E@woais.com>
Cathy Huang wrote:
>
> Say
> $IMAGE = http://www.women.com/guide/guide/gifs/nav.7.gif
>
> [code]
>
> How can I get $END = nav.7.gif? I just want to get the string between
> the last / and the end of the line.
Using $IMAGE =~ /\/(.*?)$/i doesn't work because .* is greedy and
matches the '/' character. It matches everything, as much as it can. Try
this:
$IMAGE =~ /\/([\w\+-~\&\%#]*?)$/i
That should match just about every possible item, since \w is basically
[a-zA-Z_0-9]. I added extras which I know can be in the last part of a
URL. There are probably others.
--
Wesley Miaw wesley@woais.com
World of Artists Internet Services http://www.woais.com/
71 Middlesex Drive Tel: 518-439-0412
Slingerlands, NY 12159 FAX: 518-439-9722
------------------------------
Date: Mon, 23 Jun 1997 13:06:39 -0500
From: Chris Mason <cmason@ti.com>
Subject: Hash question.
Message-Id: <33AEBB2F.7CA6@ti.com>
All-
I have a hash which may have duplicate entries (multiple similar
keys). Is there anyway I can get at the data behind those now invisible
duplicate keys? (the data I get right now when I try to access a dup is
just one random value)
I thought of two ways of hacking around this:
1. When inserting, if you see a dup, find a unique hash key by
appending a number to the key you have. Like:
fookey, fookey_1, fookey_2,...
2. A duplicate hash entry is actually a sub hash (or an array) of the
multiple entries on that key.
Anyone have any better ideas?
-c
--
Chris Mason -- <cmason@ti.com> -- Texas Instruments Software
"...the monstrous thing is not that men have created roses out of
this dung heap, but that...they should _want_ roses." -H. Miller
------------------------------
Date: Mon, 23 Jun 1997 21:14:35 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Hash question.
Message-Id: <EC8z0B.r7@world.std.com>
Chris Mason <cmason@ti.com> writes:
>All-
> I have a hash which may have duplicate entries (multiple similar
>keys). Is there anyway I can get at the data behind those now invisible
>duplicate keys? (the data I get right now when I try to access a dup is
>just one random value)
Not invisible, overwritten. When you assign a new element with the
same key, the old one is gone.
The same way you can say:
$foo = 5;
$foo = 10;
and there is no way to access the "5", if you say:
$foo{foo} = 5;
$foo{foo} = 10;
The "5" is still gone.
> 1. When inserting, if you see a dup, find a unique hash key by
>appending a number to the key you have. Like:
>fookey, fookey_1, fookey_2,...
> 2. A duplicate hash entry is actually a sub hash (or an array) of the
>multiple entries on that key.
>Anyone have any better ideas?
Number 2 seems to be the easiest to code and to access, but instead of
making just the duplicates multidimensional, why not just make your
data structure a hash of array of values.
while you're loading the hash, just use push new elements onto the
arrays contained in the hash:
while(($key, $value) = something_that_is_returning_the_data) {
push @{$hash{$key}}, $value;
}
and now each element of %hash will contain an array of one or more
elements. So when you want to access those elements:
foreach $key (keys %hash) {
# this loops as many times as there are dups
foreach $value ( @{$hash{$key}} ) {
# do something with the value
}
}
--
Andrew Langmead
------------------------------
Date: Sat, 21 Jun 1997 20:34:56 +0100
From: mike <esupu@warwick.ac.uk>
To: Gilbert Midonnet <glm@panix.com>
Subject: Re: Llama question
Message-Id: <Pine.SOL.3.95.970621202959.26762B-100000@crocus>
On 19 Jun 1997, Gilbert Midonnet wrote:
> #!/usr/local/bin/perl5
> print "Enter the list of strings:\n";
> @list = <STDIN>;
> @reverselist = reverse(@list);
> print @reverselist;
>
> The problem in this example is in the input of information. There
> is no end to the list desired.
The above code work perfectly fine with me. When you want to end
the input, you must type ^D to terminate the input.
> If I input the data using a scalar variable and then put the scalar
> variable into an array, and ask the program to print out the array
> variable, that too doesn't work.
>
> EXAMPLE:
>
> $a = <STDIN>;
>
> ...
>
> @a = ($a,$b,$c);
> print @a;
>
This code sounds alright to me. It should work. I think you should
check whether your perl is 'ok' or not.
Yours sincerely,
mike mah
------------------------------
Date: Mon, 23 Jun 1997 18:36:04 -0600
From: darkmanlives@hotmail.com
Subject: Making a MUD with CGI
Message-Id: <867104761.12007@dejanews.com>
Hi all,
I need to know how I can make a multi-user-dungeon with Perl 5.0...
it can be done, I've seen it, but I am quite new at Perl so be
patient with me while I explain... I want to make a small adventure
game in CGI for telnet... So, if you could give me a brief overview
of what I need and how to use it, I would be very greatful.
Thanx.
David Hudson
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: 23 Jun 1997 22:24:19 GMT
From: lparillo@newshost.li.net (Parillo)
Subject: Re: microsoft personal web server parsing perl scripts
Message-Id: <5omt2j$ad2@linet06.li.net>
Try http://www.endcontsw.com/people/evangelo/Perl_for_Win32_FAQ.html
and also read the Microsoft Knowledge Base article covering this issue,
"Configuring and Testing a PERL [sic] Script with IIS,"
(http://www.microsoft.com/kb/articles/q150/6/29.htm).
Ralf =?iso-8859-1?Q?L=F6ffler?= (hexe_lenggries@t-online.de) wrote:
: Can't find any documentation how to configure the microsoft personal web
: server, so it parses .pl files. Must be some registry keys. Any hints
: will be appreciated
: ralf
------------------------------
Date: 23 Jun 1997 22:53:33 GMT
From: felix@chance.em.nytimes.com (felix k sheng)
Subject: OOP - class variables and inheritance?
Message-Id: <slrn5qtvqs.7qi.felix@chance.em.nytimes.com>
hello all,
i think i've checked the book and man pages and have not discovered
the answer to my dilemma. suppose i have a module WingedThing
in which is @appendages = qw(wings feet). then i have a module
Bird which @ISA=('WingedThing') and it has @appendages=qw(wings feet beak).
(ok so a beak isn't really an appendage). now in WingedThing is
a method pringAppendages which goes and looks at the array and
prints them out. if i don't define this in Bird it finds the method
in WingedThing and prints out "wings feet". however, i'd like
it to print out "wings feet beak". is this possible to do? am i
missing something terribly obvious? any help is appreciated. thanks!
'lx
--- felix sheng pager 800 979 2171
programmer tel 212 597 8069
the new york times electronic media company e felix@nytimes.com
------------------------------
Date: 23 Jun 1997 22:29:39 GMT
From: toutatis@remove.this.toutatis.net (Toutatis)
Subject: Passing object references to a subroutines
Message-Id: <toutatis-ya023180002406970030030001@news.euro.net>
Hello,
Quite new to perl, etcetera etcetera, here's my problem:
In somescript.pl i create a databasehandle like this:
use DBI;
$drh = DBI->install_driver( 'my_driver' ) ;
$dbh = $drh->connect( 'localhost', 'my_database', '' ) ;
and now, i want to give this handle to another script,
like this:
$answer = otherscript::subroutine($dbh) || exit(0);
Other script:
use DBI;
sub one {
my $dbh = shift @_;
return two($dbh);
}
sub two {
$cursor = $dbh->prepare( "some query" )
$cursor->execute;
etcetera.
}
Now this doesn't work, because i understand &^%$^ about
object oriented programming, but maybe someone would like to tell me
how i pass such a filehandle. (Yeah, have the perlbook, and 've
read it too. Now working on understanding it :-) )
------------------------------
Date: 22 Jun 1997 15:22:20 +1200
From: Carey Evans <c.evans@clear.net.nz>
Subject: Re: Perl SIGINT Handling
Message-Id: <87oh8zfhjn.fsf@psyche.evansnet>
Doug Brink <doug.brink.ms@unocal.com> writes:
[snip]
> The binaries and the rsh are started with system() calls.
>
> Any idea how to make it behave like the bourne shell versions?
Use fork()/exec()/waitpid() to roll your own system() without ignoring
SIGINT. I've used:
sub my_system {
my $pid = fork;
if (! defined $pid) { return -1;
} elsif ($pid) { return waitpid($pid, 0);
} else { exec(@_) or exit $!;
}
}
--
Carey Evans <*> c.evans@clear.net.nz
"Our mail program accidentally deleted our remove list."
- Real quote from UCE
------------------------------
Date: Fri, 20 Jun 1997 16:53:33 +0100
From: b.wilkinson@pindar.co.uk (Bob Wilkinson)
Subject: Re: PERL to Oracle
Message-Id: <b.wilkinson-2006971653330001@ip57-york.pindar.co.uk>
In article <01bc7b2d$8f08e1c0$8add76a2@unity-94.us.gases.boc.com>, "C.
Duncan Hudson" <duncan.hudson@us.gases.boc.com> wrote:
> I have a need to read a file off a Windows NT machine and update an Oracle
> 7 (also NT) database from the records contained in the file. Is this
> something that I can do with PERL, without having to buy canned software?
> If so, how would I go about doing it? Thanks in advance,
>
>
> C. Duncan Hudson
> duncan.hudson@us.gases.boc.com
Hello,
This is all possible using software available under the GPL. A good
starting point is
http://www.hermetica.com/technologia/DBI/
Bob
--
Do what thou wilt shall be the whole of the law.
------------------------------
Date: Sat, 21 Jun 1997 20:21:25 +0100
From: mike <esupu@warwick.ac.uk>
To: Peter.J.Scott-remove-to-email@jpl.nasa.gov
Subject: Re: print "Hi", last ...
Message-Id: <Pine.SOL.3.95.970621201701.26762A-100000@crocus>
On 19 Jun 1997, Peter Scott wrote:
>
> while (1) {
> print "Yes\n", last if 1;
> print "No\n";
> }
> print "Done\n";
>
I can't see any reason you want to write the above code.
Since while (1) always execute and you just want to print yes
once. Why not write the following code:
if (1) { print "Yes\n","Done\n";}
Yours sincerely,
mike
------------------------------
Date: Mon, 23 Jun 1997 22:16:33 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: reading a data file?
Message-Id: <EC91vL.MMx@world.std.com>
Brandon <weekend_warrior@mindless.com> writes:
>Hi I'm looking to make this script of mine a little more bareable.
>I have tried, for days, to make this into a data file called by the
>script. No luck!
>What I need the script to do is read a data file with the information of
>the users in a format like:
>1234 = someone@somewhere.com
>4321 = someonelse@somewhere.com
something like:
open USERS, 'users.dat' or die "Can't read users file: $!\n";
while(<USERS>) {
# use regular expression to find matching lines
if(/(\d+)\s=\s(.*)/) { # if we have num., space, equalsign, space, otherstuff
$users{$1} = $2;
}
}
$id = $users{$CONFIG{recipient}} or error('bad id');
or if you only need to find one user id in the course of the script:
while(<USERS>) {
if(/$CONFIG{recipient} = (.*)/o) {
$id = $1;
last; # we found the id, quit the loop
}
}
close USERS;
error('bad id') unless $id; # we went through the file, but didn't find it.
>or
>1234
>someone@somewhere.com
>4321
>someonelse@somewhere.com
which would be more like:
open USERS, 'users.dat' or die "Can't open users.dat file: $!\n";
while($id = <USERS>) { # read id from file.
$email = <USERS>; # read email address from file.
$users{$id} = $email;
}
$id = $users{$CONFIG{recipient}} or error('bad id');
or
while(<USERS>) {
if(/$CONFIG{recipient}/o) { # if we found it
$id = <USERS>; # the next line is the e-mail address
last;
}
}
If the file is getting so big that searching through it is time
consuming, you can put the address in a DBM file and read them like this:
use NDBM_File;
use Fcntl;
tie(%users, NDBM_FILE, 'users.dbm', O_RDONLY, 0444);
$users{$CONFIG{recipient}} or die error('bad id');
Then looking up a key takes a fixed amount of time.
--
Andrew Langmead
------------------------------
Date: Mon, 23 Jun 1997 22:58:58 GMT
From: tram@olympic.seas.ucla.edu (Tri Tram)
Subject: regular expressions
Message-Id: <EC93uB.How@seas.ucla.edu>
Can somebody please help me with the regular expressions? I have the
following:
text #(text)
text #(more test)
test #(text and more text)
I want to change it to:
text add_text(text)
text add_text(more_text)
test add_text(text_and_more_text)
thanks for your help.
-----------------------------------------------------------------
Tri Tram, Computer Science and Engineering at UCLA
http://www.seas.ucla.edu/~tram
------------------------------
Date: Sat, 21 Jun 1997 13:29:14 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: John Klassa <klassa@gumby.ivc.com>
Subject: Re: safely opening a file while under assumed UID/GID
Message-Id: <Pine.GSO.3.96.970621132631.24220A-100000@kelly.teleport.com>
On 18 Jun 1997, John Klassa wrote:
> Page 343 of the new Camel has an example of using an "open" to "|-", and
> notes that doing so is a good way to safely open a file when running
> under an assumed UID or GID... Why is that, exactly? To avoid shell
> interpretation of arguments?
The author of that example was showing how the child process could give up
its privileges before opening a file on a user's behalf, while the parent
process still retained its suid abilities. Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 23 Jun 1997 15:09:36 GMT
From: "John Moore" <johnmoore@pdsi-software.com>
Subject: Re: socket under solaris
Message-Id: <01bc7fe7$70794560$d3043982@germ>
Jan ' Kozo ' Vajda <jvajda@ns.somi.sk> wrote in article
<5nr3u8$orc@gringo.somi.sk>...
> how use Socket.pm under solaris 2.5.x ???
>
> i tried it, but I resolved error:
> socket: Protocol not supported
>
> thx ..
>
> K O Z O
> ====================================
> e-mail: Jan.Vajda@somi.sk
> URL: http://www.sanet.sk/~vajda
>
>
>
Kozo, Had the same problem w/ perl 4. As I remember perl defines
$SOCK_STREAM as 0 but solaris uses 2. The following does work under
solaris 2.5.
#!/usr/local/bin/perl
($port) = @ARGV;
$port = 3000 unless $port;
$AF_INET = 2;
$SOCK_STREAM = 2;
$sockaddr = 'S n a4 x8';
($name, $aliases, $proto) = getprotobyname('tcp');
if ($port !~ /^\d+$/) {
($name, $aliases, $port) = getservbyport($port, 'tcp');
}
print "Port = $port\n";
$this = pack($sockaddr, $AF_INET, $port, "\0\0\0\0");
select(NS); $| = 1; select(stdout);
socket(S, $AF_INET, $SOCK_STREAM, $proto) || die "socket: $!";
bind(S,$this) || die "bind: $!";
------------------------------
Date: Sun, 22 Jun 1997 06:21:14 -0700
From: Clayton Weaver <cgweav@eskimo.com>
Subject: stdin, stdout, exec
Message-Id: <Pine.SUN.3.96.970622054724.21389A-100000@eskimo.com>
If I assign <STDIN> to <STDOUT>, $| = 1;, print <STDOUT> "$data";, and
exec, is the data available on <STDIN> of the execed process?
{process original stdin and @ARGV if any up here}
while ($ARGV[0] != $someval)
{
open(STDIN, ">-");
$test = "test";
$| = 1;
print STDOUT "$test";
exec('someprog', 'iteration_flag', ' '); # ' ' = "don't use /bin/sh"
}
{rest of program}
Someprog inherits the file descriptors of the process execed from
(assuming no error on the exec), so it should have the data written on
it's own stdin. Any obvious problem with doing an exec loop like this
besides handling error messages from the system call?
(It's just to save some process creation overhead while handling data
without having the optimizer rearrange expressions that need to be
evaluated in sequence. Maybe there is a builtin for this?)
Regards, Clayton Weaver cgweav@eskimo.com (Seattle)
------------------------------
Date: Mon, 23 Jun 1997 13:10:55 -0700
From: Howard Yen <howard.yen@mci2000.com>
Subject: Use Perl in C
Message-Id: <33AED84F.6C3C@mci2000.com>
Hi
I have been trying to run Perl subroutines in my C program.
Because I need the text parseing power of Perl and the
speed of C.
How do I run Perl subroutine from C. I have tried reading the
documents however I got as far as compling very
simple perl subroutines (sub's that does not use any modules)
The perl sub I wrote uses the libwww package. Can
someone show me exactly how I can embed a perl sub that uses
the libwww pacakage?
hy
------------------------------
Date: Mon, 23 Jun 1997 21:58:18 +0100
From: mike mah <esupu@warwick.ac.uk>
Subject: what is my, lc and etc and where to learn it?
Message-Id: <Pine.SOL.3.95.970623215255.15875A-100000@lily>
hi perl gurus,
I feel so strange, you know. Although I finished reading Learning
Perl, I never encounter my, lc and etc. Why is that so? Where can I get to
learn complete (probably advance features) set of command (like above)?
Any help is very appreciated. Thanks in advance.
Let's strike for exellent.
Yours sincerely,
mike mah
------------------------------
Date: Sat, 21 Jun 1997 13:39:55 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: David Kramer <Dskramer@concentric.net>
Subject: Re: When do I call srand?
Message-Id: <Pine.GSO.3.96.970621133024.24220B-100000@kelly.teleport.com>
On Wed, 18 Jun 1997, David Kramer wrote:
> I am trying to find out the "scope" of srand.
Here's the story of what srand really does.
The numbers returned by rand() aren't truly random. Instead, they are the
same sequence every time you run your program. Many folks (and even some
authors of documentation) will claim that srand() seeds rand() to supply a
new random sequence each time. THIS IS NOT TRUE. rand() still supplies the
_exact_same_ random sequence (on a properly installed and configured
system), but srand() starts that sequence at a new (putatively random)
spot. That's all srand() does.
> Does it only affect rand() in the one process, or all processes?
It only affects the current process. If you're going to fork and then use
rand(), you probably want to use srand after forking so as to have
different random numbers in the parent and the child - unless, of course,
you want the same ones in both! :-)
> If I have one perl program that require()'s another,
That's probably not what you have. You probably have library subroutines
that you're require()ing, but they're still part of the same perl process.
> and both need random numbers, should I call srand() in the require()'ed
> program, or only the outer program?
Once for each process is sufficient. In 5.004, Perl even calls srand() for
you if it sees that you haven't done so before you first use rand().
> Also, exactly what does srand expect as a parameter? What range of number
> does it expect?
It should be able to use any number you give it, but a 32-bit integer is
(almost certainly) what's being used internally, unless I'm mistaken. But
the default (in 5.004 and later) should be suitable for anything short of
crypto/security work. In that case, you want to check out
Math::TrulyRandom on CPAN. Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 647
*************************************