[6352] in Perl-Users-Digest
Perl-Users Digest, Issue: 974 Volume: 7
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 19 13:27:25 1997
Date: Wed, 19 Feb 97 10:00:23 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 19 Feb 1997 Volume: 7 Number: 974
Today's topics:
A form-to-mail perl script needed! Heeeeeeeeeeelp! (Thodoris Tsioupros)
ARGV fails on Win32/NT <troruud@online.no>
Closing inherited (and anonymous) file descriptors in U (Clinton Pierce (R))
Re: debugging perl & html (brian d foy)
Re: Exemples de petits prog. en perl ? <seay@absyss.fr>
How to do case statements in perl <rdarnese@nortel.ca>
Re: How to do case statements in perl (Mike Heins)
Re: How to do case statements in perl (Jagadeesh Venugopal)
Re: learning perl <david@bradda.demon.co.uk>
Re: Length of an assoc. array? (Mike Stok)
Re: Length of an assoc. array? (Lack Mr G M)
Re: Matt's Counter Archive (Clay Irving)
Passing command line parameters <jtseng@wauug.erols.com>
PERl (via www) Databases from the ground up <MoNoLiTH+@CMU.EDU>
Re: Perl for Win32 wrapper for Java <jservice@jabez.rd.hydro.on.ca>
Re: Perl program in crontab problem (Clay Irving)
Re: Perl question, re: POSIX setpgrp (Danny R. Faught)
Perl using win32s <cpgsales@erie.net>
Re: PerlWin32-95:Yes-NT4:No (Jonathan Peterson)
Re: PROGRAM: how to check for nice/valid email address (Jonathan Peterson)
Returning hash of arrays in a subroutine <jsyre@dcaca091.ca.boeing.com>
Re: Returning hash of arrays in a subroutine <seay@absyss.fr>
Re: Returning hash of arrays in a subroutine (Mike Stok)
Segmentation fault embed from tpj (Leonhard Brenner {13031} 7149 [ ])
Symbol reference error in embed examples (Leonhard Brenner {13031} 7149 [ ])
Re: valid URL regexp (brian d foy)
Re: Why doesn't gethostbyaddr return a value? <rra@cs.stanford.edu>
Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 19 Feb 1997 17:40:37 GMT
From: thodoris@hol.gr (Thodoris Tsioupros)
Subject: A form-to-mail perl script needed! Heeeeeeeeeeelp!
Message-Id: <5efdul$4qk$1@news.hol.gr>
Hi all
I am a 17 year old boy from Greece and I have uploaded my
personal web page to a local WWW server (www.chalkida.hol
gr/people/user_pgs/thodoris).
I really want to add a form to it, requesting the
visitor's NAME, EMAIL address and COMMENTS about the page.
The Webmaster has told me that I have to make the form-to
-mail script using PERL. I have no idea about this
language but I am familiar to Unix-like systems.
Is it easy to make a script that will take the text from
the form and send it to my email address ?
(thodoris@hol.gr) ? Could any1 help? Does anyone have
allrady such a script made ? Pleeeeease lend a hand!
Looking forward to hearing from you,
Thodoris Tsioupros ( Chalkida / Greece )
H E E E E E E E E E E E E E E E E E E E E E L P !
------------------------------
Date: 19 Feb 1997 15:08:10 GMT
From: "Trond Ruud" <troruud@online.no>
Subject: ARGV fails on Win32/NT
Message-Id: <01bc1e78$1932ce00$15e17a94@troruud.sol.no>
Hi,
Does anyone know about this problem on NT installations:
The script argument list ARGV is always empty!
I.E:
when issuing:
$ test.pl arg1 arg2
the error message below is always displayed and the script is killed
but the script name, ($0), never appears in the message!
So no ARGV values seem to be set at all !?
die "$0 requires a command line argument$#argv \n\a" if $#argv <0;
Regards
Trond Ruud troruud@online .no
------------------------------
Date: 19 Feb 1997 14:38:26 GMT
From: cpierce1@cp501.fsic.ford.com (Clinton Pierce (R))
Subject: Closing inherited (and anonymous) file descriptors in UNIX/Perl
Message-Id: <5ef392$51o1@eccws1.dearborn.ford.com>
In Perl, can I close an arbitrary file descriptor? What I have is this:
* UNIX Process A opens up file descriptors 4,5,6...n in addition to 0,1,2
(STDIN, STDOUT, STDERR)....
* UNIX Process A forks creating process B with the open descriptors
0,1,2 also 4,5,6...n Process B execs a Perl script.
* Process A exits, orphaning Process B. (This is intentional.)
* Process B attempts to daemonize itself by closing all file descriptors,
changing to root directory, setting own process group, etc...
What is inevitably happening is that process B can NEVER close the file
descriptors 4,5,6...n because it has no references to them. It seems that
Perl can't deal with an arbitrary file descriptor for close(). How can
I write a reliable function to close them?
The C Shell handles this by just closing all of the damned desciptors
whether they need it or not:
for (f = 0; f < NOFILE; f++)
if (f != SHIN && f != SHOUT && f != SHDIAG && f != OLDSTD &&
f != FSHTTY
&& f != 25
)
(void) close(f);
How can I accomplish the same thing in Perl?
PS: The process "A" I'm trying to defeat is rlogind(1).
--
-----------------------------------------------------------------o------
Clinton A. Pierce | "If you rush a Miracle Man | \ / \ /
cpierce1@ford.com | you get rotten miracles." | \ G /
DCI, Inc. on loan to Ford|--Miracle Max, The Princess Bride| / \ / \
-------------------------------------------------------------Freemason--
Geek Code: GCM/GCSd-(++)s+:+a-C++UA++++$UIS+++$UL+++P++++L++E---W++N++w
---Ot++(+++)5+X+R-tv-b+++DI++++G++e+>++h----r+++y+++(--)>y*
http://www.dcicorp.com/~clintp
------------------------------
Date: Tue, 18 Feb 1997 10:54:12 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: debugging perl & html
Message-Id: <comdog-1802971054120001@nntp.netcruiser>
In article <cuttE5tA4E.5vM@netcom.com>, cutt@netcom.com (Paul S. Cutt) wrote:
> I wonder what people are using to debug perl scripts when called from an
> html page ? I know about perl debugger but this is run from the command
> line. If my html page calls my perl script how can I get the debugger at
> that point to execute so I can continue debugging ?
if you are using CGI.pm you can use the built in debugging features. you
can also set environment variables (REQUEST_METHOD, QUERY_STRING, etc.)
so that you can test your script from the command line -- using the
debugger if you like.
--
brian d foy <URL:http://computerdog.com>
unsolicited commercial email is not appreciated
------------------------------
Date: Wed, 19 Feb 1997 15:55:50 +0000
From: Douglas Seay <seay@absyss.fr>
To: Dominique BAGOT <Dominique.BAGOT@cetp.ipsl.fr>
Subject: Re: Exemples de petits prog. en perl ?
Message-Id: <330B2286.1C0A@absyss.fr>
Dominique BAGOT wrote:
> =
> Bonjour a tous,
> =
> connaissez-vous un (des) sites ayant des programmes
> ecrits en perls a des fins pedagogiques. J'ai fait du perl il y a
> assez longtemps et j'aimerais m'y remettre rapidos a l'aide
> de petits exemples.
> =
> Merci, Dom
> =
> Dominique.BAGOT@cetp.ipsl.fr
The camel has lots of good examples, complete with
comments and everything.
I bought my copy of the camel at Le Monde En Tique,
which is in the 5eme, accross from L'ile St. Louis.
According to the page http://www.lmet.fr/
[LI] PROGRAMMING PERL 2ED
WALL - O'REILLY - 259 FF - Disponible =E0 la librairie
ISBN : 1-56592-149-6 =
=
=
[LI] PROGRAMMATION EN PERL 2ED
WALL - ITPS - 280 FF - Disponible chez l'=E9diteur
ISBN : 2-84177-004-4
Sorry for replying in english, but my french is
not very good.
doug seay
seay@absyss.fr
------------------------------
Date: 19 Feb 1997 16:09:25 GMT
From: Richard Arnesen <rdarnese@nortel.ca>
Subject: How to do case statements in perl
Message-Id: <5ef8jl$5h5@nrtphc11.bnr.ca>
The subject line says it all.
--
Richard D. Arnesen Jr. "Bill Clinton's Promises have the
Unix DCA Support, Nortel lifespan of a Big Mac on AirForce
The opinions expressed are MINE One" - Rep. Susan Molinari
no else can have them Romans 6:23, 1Cor 4-8, John 3:16
------------------------------
Date: 19 Feb 1997 16:50:23 GMT
From: mheins@prairienet.org (Mike Heins)
Subject: Re: How to do case statements in perl
Message-Id: <5efb0f$5ft@vixen.cso.uiuc.edu>
Richard Arnesen (rdarnese@nortel.ca) wrote:
: The subject line says it all.
:
And so does the perlsyn(1) man page.
--
Regards, ___ ___
Mike Heins [mailed and posted] http://www.iac.net/~mikeh|_ _|____ |_ _|
Internet Robotics | || _ \ | |
This post reflects the Oxford, OH 45056 | || |_) || |
opinion of my employer. <mikeh@iac.net> |___| _ <|___|
513.523.7621 FAX 7501 |_| \_\
------------------------------
Date: 19 Feb 1997 17:00:12 GMT
From: jvenu@ctp.com (Jagadeesh Venugopal)
Subject: Re: How to do case statements in perl
Message-Id: <5efbis$rnr@concorde.ctp.com>
In article <5ef8jl$5h5@nrtphc11.bnr.ca> Richard Arnesen <rdarnese@nortel.ca> writes:
>The subject line says it all.
>
>--
>Richard D. Arnesen Jr. "Bill Clinton's Promises have the
Please look in the 2d edition Camel Book page 103.
--
/\/\ |Jagadeesh K. Venugopal, jvenu@ctp.com |http://w3.ctp.com/~jvenu
/ /_.\|Cambridge Technology Partners, Inc. |http://www.ccs.neu.edu/home/jkvg
\ /./|304 Vassar St. Cambridge, MA 02139 |
\/\/ |Phone: 617.374.2028 FAX: 617.374.8300 +
------------------------------
Date: Wed, 19 Feb 1997 15:24:58 +0000
From: David Darwent <david@bradda.demon.co.uk>
Subject: Re: learning perl
Message-Id: <rsT+gAAKtxCzIwLT@bradda.demon.co.uk>
In article <Dke0yDA1FJAzIweq@bradda.demon.co.uk>, David Darwent
<david@bradda.demon.co.uk> writes
>Hi
>
>Having realised that HTML has it's limits I decided that I would like to
>write CGI for web pages and after reading about perl I decided that perl
>was the ideal language for CGI. So I bought a book and started to read.
>But I soon realised that it wasn't going to be as easy as I thought. As
>this is my first experience with programming.
>Is this why I am find perl difficult? Am I trying to run before I can
>walk? Is there a langange that I should tackle first, maybe BASIC or
>PASCAL? Or should I just persevere with perl?
>
>Any help will be much appreciated
>
>
>
> All the best,
> David Darwent
Hi, it's me (David) again,
I'd just like to thank everyone who emailed me with their help
and suggestions. They were all very useful.
Thanks again
All the best,
David Darwent
------------------------------
Date: 19 Feb 1997 15:50:10 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Length of an assoc. array?
Message-Id: <5ef7fi$5go@news-central.tiac.net>
In article <5ef253$bjd$1@goliat.eik.bme.hu>,
Kovacs Anita <anita@unicorn.sch.bme.hu> wrote:
>Can I get it somehow?
You can say
$elements = keys %hash;
which gives the count of key/value pairs in the hash.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
Date: 19 Feb 1997 16:00:02 GMT
From: gml4410@ggr.co.uk (Lack Mr G M)
Subject: Re: Length of an assoc. array?
Message-Id: <5ef822$hid@ukwsv3.ggr.co.uk>
In article <5ef253$bjd$1@goliat.eik.bme.hu>, anita@unicorn.sch.bme.hu (Kovacs Anita) writes:
|> Can I get it somehow?
|>
|> Thankx
Associative arrays don't have a length.
They are like containers (and what is the length of a container?).
They *do* have a number of contents, and you can get that by:
$hash_count = scalar(keys %hash);
--
----------- Gordon Lack ----------------- gml4410@ggr.co.uk ------------
The contents of this message *may* reflect my personal opinion. They are
*not* intended to reflect those of my employer, or anyone else.
------------------------------
Date: 19 Feb 1997 10:01:56 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: Matt's Counter Archive
Message-Id: <5ef4l4$mqh@panix.com>
In <01bc1524$c27cdc60$0f02000a@shadow> "Shadow" <Shadow@r56h108.res.gatech.edu> writes:
>I downloaded and configured http://www.worldwidemart.com 's Counter Cgi
>program, and fly too ! And when I execute it in Telnet
>it zaps the makings of a gif if you were to open one up in an editor, but
>on The web when I go to my site to try to use it, it doesn't show.
Check the permission of the directory the GIF file is written to -- I bet
it doesn't have read/write permissions for other.
--
See the happy moron,
He doesn't give a damn, Clay Irving N2VKG
I wish I were a moron, clay@panix.com
My God! Perhaps I am! http://www.panix.com/~clay
------------------------------
Date: Wed, 19 Feb 1997 12:30:38 -0500
From: Joe Tseng <jtseng@wauug.erols.com>
Subject: Passing command line parameters
Message-Id: <Pine.LNX.3.95.970219122727.4676B-100000@wauug.erols.com>
I checked with my blue camel book but I could not find the answer.
I would like to know if there is any way to pass any parameters to a
script directly on the command line. Right now I have parameters being
passed as:
$foo = <STDIN>;
Somehow I'm sure there's another way to do this...
Joe Tseng
(301)523-4877
mailto:jryan@radix.net | http://206.136.44.4/
unzip ; touch ; finger ; mount ; gasp ; yes ; umount ; sleep
1996-97 #13 Terrapins Basketball (19-6) -- It's AWWWsome BAABEEEEE!!!!!
Friends don't let friends become Orioles fans! GO YANKEES!!!!!
------------------------------
Date: Wed, 19 Feb 1997 10:24:11 -0500
From: Aveek Datta <MoNoLiTH+@CMU.EDU>
Subject: PERl (via www) Databases from the ground up
Message-Id: <In2lgP_00iWn04b1Y0@andrew.cmu.edu>
I run a Linux system with a simple database system (a given directory is
the database, files in that directory are records, and each file is
ASCII formatted with data). However, with over 30,000 records, this is
getting slow and it's hard to keep the databases in sync. Hence I'm
looking for a simple, easy, and free relational database that I can use
to maintain a database that will be accessed primarily through a Web
based interface.
I've been browsing the Free-Databases and the CPAN archive and have seen
the DBI/DBD stuff, but am pretty confused. Most if it seems to require
something like Oracle or knowledge of SQL. Is there any more simplistic
software available?
Thanks!
Aveek Datta _ _ _ _ Email: aveek@andrew.cmu.edu
_ __ ___ _ _ ___| (_) |_| |_ |W| HomePage: datta.ml.org
_| ' \/ _ \ ' \/ _ \ | | _| ' \ _ |E| FreeDNS: www.ml.org
(_)_|_|_\___/_||_\___/_|_|\__|_||_(_) |B| Work: www.itc.cmu.edu
------------------------------
Date: Wed, 19 Feb 97 17:16:55 GMT
From: Jim Service <jservice@jabez.rd.hydro.on.ca>
Subject: Re: Perl for Win32 wrapper for Java
Message-Id: <yluohdg3edg.fsf@jabez.rd.hydro.on.ca>
Joe Bragg <Joe.Bragg@nt.com> writes:
>
> I am using Perl for Win32 Build 303 on a Window NT 4.0 machine with
> Microsoft IIS 2.0 Version 4.0 and JDK 1.0.2.
>
> The problem I am having is executing a Java application from within a
> Perl CGI. If I run the Perl script from the DOS command line it works
> fine, but when I try to run it though my Netscape browser I get
> "Document contains no data". The header information is sent from the
> Perl script but the content (<HTML>...</HTML>) is created in the Java
> application and passed back though a scalar ($java=qx(java Report parm1
> parm2 ...)) then printed (print"$java";).
>
> The same Perl script and Java application work great on my Windows 95
> machine using WebSite 1.1 and Perl 4.036.
>
> Can anybody give me some insight into what the problem might be?
On Windows NT your script runs using the perl dll so it also has to return
the appropriate HTTP response as well as the Content-type: header.
Look at part 7 of the Perl for Win32 FAQ at
http://www.endcontsw.com/people/evangelo/Perl_for_Win32_FAQ_7.html
for more details.
>
> Thanks in Advance,
> Joe Bragg
> Email: Joe.Bragg@nt.com
--
James (Jim) R.R. Service Internet: jservice@oht.hydro.on.ca
Ontario Hydro Technologies
800 Kipling Ave. - Room KR128 FAX: (416) 207-5623
Toronto, Ontario, CANADA M8Z 5S4 voice: (416) 207-6946
------------------------------
Date: 19 Feb 1997 10:29:25 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: Perl program in crontab problem
Message-Id: <5ef68l$s1p@panix.com>
In <5ef0fc$h9u@fridge-nf0.shore.net> nvp@shore.net (Nathan V. Patwardhan) writes:
>Clay Irving (clay@panix.com) wrote:
>: #!/usr/local/bin/perl
>:
>: use lib "/usr/local/lib/perl5";
>:
>: $date=`date`;
>: ($day,$mm,$dd,$time,$tz,$yy) = split(/\s+/,$date);
>Why bother with the backticks if you don't have to use them?
>I'd suggest using localtime().
I originally had:
$date = localtime();
I tried backticks, because I originally thought the program couldn't find
the Perl functions. However, this error message:
/usr/local/bin/web-stats.pl: use: not found
/usr/local/bin/web-stats.pl: =Wed: not found
lead me to believe that the system isn't running the program as a Perl
program. This is the entry in /var/cron/log:
> CMD: /bin/sh /usr/local/bin/web-stats.pl 2>&1 | mail clay
Uh-oh... See! I knew it was something silly and stupid. The entry in
crontab is:
01 0 * * * /bin/sh /usr/local/bin/web-stats.pl 2>&1 | mail clay
Silly me... Run this from a command line:
/bin/sh /usr/local/bin/web-stats.pl
and you'll get the error messages I'm experiencing....
Pass the dunce cap, please.
We now return your monitor to more intelligent questions about Perl.
--
See the happy moron,
He doesn't give a damn, Clay Irving N2VKG
I wish I were a moron, clay@panix.com
My God! Perhaps I am! http://www.panix.com/~clay
------------------------------
Date: 19 Feb 1997 09:09:36 -0600
From: faught@convex.hp.com (Danny R. Faught)
Subject: Re: Perl question, re: POSIX setpgrp
Message-Id: <5ef53g$kcj@feep.rsn.hp.com>
In article <pzraigyshr.fsf@eeyore.ibcinc.com>,
Roderick Schertler <roderick@gate.net> wrote:
>On Fri, 14 Feb 1997 16:31:53 GMT, Chris Vo <chrisv@on.bell.ca> said:
>>
>>>> POSIX setpgrp can't take an argument at ./check_ntp line 21.
setpgrp isn't a POSIX function at all, is it?
>Porters, what do you think of this patch?
...
> DIE("POSIX setpgrp can't take an argument");
What POSIX setpgrp? There's no such thing.
--
Danny Faught -- HP-Convex -- Software Test Alchemist
"Everything is deeply intertwingled." (Ted Nelson, _Computer Lib_)
------------------------------
Date: Wed, 19 Feb 1997 11:53:59 -0500
From: Consolidated Premium Group Sales Office <cpgsales@erie.net>
Subject: Perl using win32s
Message-Id: <330B3027.180D@erie.net>
Does anyone have experience using win32s to run perl through win 3.11?
Also, what are the system requirements to run perl on a computer?
------------------------------
Date: 19 Feb 1997 15:48:05 GMT
From: jon@amxdigital.com (Jonathan Peterson)
Subject: Re: PerlWin32-95:Yes-NT4:No
Message-Id: <jon-1902971544530001@amx11.amxdigital.com>
In article <3309B8C4.260D@isr.umd.edu>, Mj Smith <mjsmith@isr.umd.edu> wrote:
> Simply, I want to delete all the files in a particular directory. So, I
> used the glob <*.*> to select all the files. This worked just find
> under Win95. But, as soon as I try it in NT4Wkstn (I logged on as full
> administrator), the same exact set of lines, give me an error as soon as
> I reach the glob. The error states roughly, that "the name specified is
> not recoginzed as an internal or external program, function...".
>
> Any thoughts?
Sounds like NT isn't expanding the glob; it's looking for a file called "*.*"
I'd have thought that `cd $Dirname` followed by `del *.*` would do it
(clumsily, though..)
Send a snippet of the perl code you are using, and I might be able to
help, I've done some Perl/NT stuff.
------------------
Opinions expressed above are not necessarily those of AMXdigital ltd.
Jonathan Peterson || jon@amxdigital.com || (+44) 0171 613 5300
"You wouldn't believe the things I've seen with your eyes."
------------------------------
Date: 19 Feb 1997 16:05:05 GMT
From: jon@amxdigital.com (Jonathan Peterson)
Subject: Re: PROGRAM: how to check for nice/valid email address
Message-Id: <jon-1902971601540001@amx11.amxdigital.com>
In article <ls3pvy2x66l.fsf@sveerara-ultra.cisco.com>,
sveerara@sveerara-ultra.cisco.com () wrote:
> I'm not sure if there are any problems with this but,
>
> sendmail -bv
>
> seems to work okay for me. man sendmail for more details...
It doesn't work for me for any domain outside my own. Gives false
positives all over the place. (eg thinks jon@qwerty.co.uk is deliverable)
Try this:
This was written to be a seperate file, required by other CGI scripts.
It does a syntax check first to catch people doing a@b.c or go@away or whatever.
If this passes it calls nslookup to see if there are MX records for that domain
(An MX record simply points to a machine that should handle email for that
domain)
If there are MX records, then it lets it though. It could check for user
with finger, but since most commercial ISP's don't have finger servers, I
didn't think it would really be worth it.
#
#Program gathers an email address, does as much
#checking as is reasonable, and adds it to a list.
#
#usage:
#&checkEmail(<emailaddress>);
#returns: 1 if valid or an error message
#
#requires that nslookup be installed properly and in the path.
#
sub checkEmail{
#
# Vars
#
local ($Address) = @_[0]; #This is the email address the user enters
local ($Domain) = ""; #This is the domain stripped from $Address
local ($QResult) = ""; #Result of nslookup on $Domain
#Test 1, for correct syntax
if ($Address !~ /\w+@.+\.(\w{2,4})$/){
return('The email address given was not properly formed.');
}
#Test 2, for existant domain
$Domain = $Address;
$Domain =~ s/.*@//;
$QResult = `nslookup -type=mx $Domain`;
if ($QResult !~ /mail exchanger/){
return("The domain or host $Domain could not be found, or had no email records."
);
}
#The address must be OK!
return 1;
}
1;
------------------
Opinions expressed above are not necessarily those of AMXdigital ltd.
Jonathan Peterson || jon@amxdigital.com || (+44) 0171 613 5300
"You wouldn't believe the things I've seen with your eyes."
------------------------------
Date: Wed, 19 Feb 1997 14:57:28 GMT
From: "John S. Syre" <jsyre@dcaca091.ca.boeing.com>
Subject: Returning hash of arrays in a subroutine
Message-Id: <330B14D8.185F@dcaca091.ca.boeing.com>
I have gathered from reading perl* [where this includes everything
I could get my hands on including (blue camel, perlref, perldata, etc.]
that I should uses references to do this, but I'm not sure about the
syntax.
I tried several variations but none worked. Would someone kindly
show me how to resolve the question marked items below?
------perl script
#!/bin/perl -w
? = ReadHostFile('host.dt') ; <== what's the declaration for the
receiving variable
?? now that I have a reference to my hash of array how do
?? I access it, for instance print a sorted list by host
sub ReadHostFile ( )
{
my ($file) = shift ;
open(HOSTFILE,"$file") ||
do {
warn "Can't open $file: $!\n";
return () ;
} ;
@hostParams = () ;
LINE:
while (<HOSTFILE> ) {
chomp();
next LINE if /^\s*#/ ; # skip comment lines
# parse CSV line
push( @hostParams, $1||$+ )
while /\s*"(([^"\\]|\\"|\\\\)*)"\s*|\s*([^",]+)\s*/g;
$hostName = shift @hostParams;
$hostHashedArray{ $hostName } = @hostParams ;
@hostParams = () ; #empty the array
?? return( ???hostHashedArray ) ; <== how do I return the
hash of arrays
}
}
--- host.dt contents---
#HostName, PlatformType, OSName, OSType
host1004, HP9000/700, HP-UX, UNIX
host1091, HP9000/700, HP-UX, UNIX
host1082, HP9000/700, HP-UX, UNIX
--
Thanks for any insight you can give me.
John Syre
Email: jsyre@dcaca091.ca.boeing.com
------------------------------
Date: Wed, 19 Feb 1997 16:46:44 +0000
From: Douglas Seay <seay@absyss.fr>
To: "John S. Syre" <jsyre@dcaca091.ca.boeing.com>
Subject: Re: Returning hash of arrays in a subroutine
Message-Id: <330B2E74.6B50@absyss.fr>
John S. Syre wrote:
>
> I have gathered from reading perl* [where this includes everything
> I could get my hands on including (blue camel, perlref, perldata, etc.]
> that I should uses references to do this, but I'm not sure about the
> syntax.
> I tried several variations but none worked. Would someone kindly
> show me how to resolve the question marked items below?
>
> ------perl script
> #!/bin/perl -w
>
> ? = ReadHostFile('host.dt') ; <== what's the declaration for the
> receiving variable
my $hash_of_arrays = ReadHostFile('host.dt');
>
> ?? now that I have a reference to my hash of array how do
> ?? I access it, for instance print a sorted list by host
>
> sub ReadHostFile ( )
> {
> my ($file) = shift ;
> open(HOSTFILE,"$file") ||
> do {
> warn "Can't open $file: $!\n";
> return () ;
> } ;
> @hostParams = () ;
> LINE:
> while (<HOSTFILE> ) {
> chomp();
> next LINE if /^\s*#/ ; # skip comment lines
> # parse CSV line
> push( @hostParams, $1||$+ )
> while /\s*"(([^"\\]|\\"|\\\\)*)"\s*|\s*([^",]+)\s*/g;
> $hostName = shift @hostParams;
> $hostHashedArray{ $hostName } = @hostParams ;
^^^^^^
scalar context means this returns
the number of elements in the array.
it should be [ @hostParams ];
> @hostParams = () ; #empty the array
> ?? return( ???hostHashedArray ) ; <== how do I return the
> hash of arrays
> }
> }
return( \%hostHashedArray );
I also notice a curious lack of "my declarations" for
everything but $file. "use strict;" would let you
know about this.
doug seay
seay@absyss.fr
------------------------------
Date: 19 Feb 1997 16:19:11 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Returning hash of arrays in a subroutine
Message-Id: <5ef95v$6r8@news-central.tiac.net>
In article <330B14D8.185F@dcaca091.ca.boeing.com>,
John S. Syre <jsyre@dcaca091.ca.boeing.com> wrote:
>? = ReadHostFile('host.dt') ; <== what's the declaration for the
> receiving variable
A reference is stored in a regular scalar.
>?? now that I have a reference to my hash of array how do
>?? I access it, for instance print a sorted list by host
See below...
> $hostHashedArray{ $hostName } = @hostParams ;
This is dangerous, the scalar assignment will leave you with the number of
elements in @hostParams in $hostHashedArray{$hostName}, you want to use []
to construct an anonymous array containing a copy of @hostParams and give
you a reference to it.
>?? return( ???hostHashedArray ) ; <== how do I return the
use the \ operator to get you a reference.
This:
#!/usr/local/bin/perl -w
use strict;
my $hashRef = &ReadHostFile ('something');
foreach my $host (sort keys %$hashRef) {
print "$host: ", join (', ', @{$hashRef->{$host}}), "\n";
}
sub ReadHostFile {
# my $file = shift ;
# local (*HOSTFILE);
# unless (open HOSTFILE, "<$file") {
# warn "Can't open $file: $!\n";
# return;
# }
my %hostHashedArray;
LINE:
while (<DATA>) { # use <DATA> to read lines after __END__
chomp;
next LINE if /^\s*#/ ; # skip comment lines
# parse CSV line
my @hostParams;
push @hostParams, ($1||$+)
while /\s*"(([^"\\]|\\"|\\\\)*)"\s*|\s*([^",]+)\s*/g;
my $hostName = shift @hostParams;
$hostHashedArray{$hostName} = [@hostParams];
}
return \%hostHashedArray;
}
__END__
#HostName, PlatformType, OSName, OSType
host1004, HP9000/700, HP-UX, UNIX
host1091, HP9000/700, HP-UX, UNIX
host1082, HP9000/700, HP-UX, UNIX
will produce this:
host1004: HP9000/700, HP-UX, UNIX
host1082: HP9000/700, HP-UX, UNIX
host1091: HP9000/700, HP-UX, UNIX
when I run it on my system. (older perl 5s might whine about
foreach my $host (sort keys %$hashRef) {
...
}
which you can replace with
{
my $host;
foreach $host (sort keys %$hashRef) {
...
}
}
)
Hope this (plus a look at the perldsc and perlobj man pages) helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
Date: 19 Feb 1997 10:32:11 -0500
From: lab@slpabu.msd.ray.com (Leonhard Brenner {13031} 7149 [ ])
Subject: Segmentation fault embed from tpj
Message-Id: <uqd3eusn75w.fsf@slpabu.msd.ray.com>
After cut and pasting regex.c and regex.pl I compiled
using:
gcc -Wall -o regex regex.c
-L/share/apl/perl5.003/lib/sun4-solaris/5.003/CORE
-I/share/apl/perl5.003/lib/sun4-solaris/5.003/CORE
-lperl -lsocket -lnsl -ldl -lm -lc -lcrypt
Then ran program using:
regex
This gave me a core dump. I am running on a solaris Ultra Sparc with
perl 5.003. I also have the CORE so if some want to help I can send the
CORE file.
Thanks in advance Lenny Brenner
------------------------------
Date: 19 Feb 1997 11:21:03 -0500
From: lab@slpabu.msd.ray.com (Leonhard Brenner {13031} 7149 [ ])
Subject: Symbol reference error in embed examples
Message-Id: <uqd20acn4wg.fsf@slpabu.msd.ray.com>
I was compiling the example,
Performing Perl pattern matches and substitutions from your C program
as follows:
lab@slpabu<cgi-bin,17>gcc -g -Wall -o matches matches.c
-L/share/apl/perl5.003/lib/sun4-solaris/5.003/CORE
-I/share/apl/perl5.003/lib/sun4-solaris/5.003/CORE
-lperl -lsocket -lnsl -ldl -lm -lc -lcrypt
Then recieved the following errors:
matches.c: In function `eval':
matches.c:13: warning: control reaches end of non-void function
matches.c: In function `match':
matches.c:27: warning: implicit declaration of function `perl_eval'
matches.c: At top level:
matches.c:84: warning: return-type defaults to `int'
matches.c: In function `main':
matches.c:98: warning: implicit declaration of function `perl_match'
matches.c:109: warning: implicit declaration of function `perl_matches'
matches.c:121: warning: implicit declaration of function `perl_substitute'
matches.c:88: warning: unused variable `j'
matches.c:137: warning: control reaches end of non-void function
Undefined first referenced
symbol in file
perl_substitute /var/tmp/cca004zl1.o
perl_matches /var/tmp/cca004zl1.o
perl_match /var/tmp/cca004zl1.o
perl_eval /var/tmp/cca004zl1.o
ld: fatal: Symbol referencing errors. No output written to matches
So I ran nm on libperl.a an found that these function were not included.
Am I looking in the wrong place or what. I am currently using perl5.003 for
Solaris.
Thanks in advance Lenny Brenner<lab@caesun.msd.ray.com>
------------------------------
Date: Tue, 18 Feb 1997 10:51:26 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: valid URL regexp
Message-Id: <comdog-1802971051260001@nntp.netcruiser>
In article <330A3C26.5236009A@plains.nodak.edu>, Darin Hawley
<dhawley@plains.nodak.edu> wrote:
> A while back I remember seeing a huge regexp for a valid URL, as well as
> a more modularized version for validating a given string as a URL. I've
> looked around in libwww.pl for an easy way of doing this without
> success. I've been hard pressed to find any examples laying around
> either. If anyone has a good answer, please post it. This would also
> make a good addition to the FAQ. Thanks...
use URI::URL;
even if you don't want to use the module, you can see how it was done :)
--
brian d foy <URL:http://computerdog.com>
unsolicited commercial email is not appreciated
------------------------------
Date: 19 Feb 1997 07:55:53 -0800
From: Russ Allbery <rra@cs.stanford.edu>
To: Matti Hultstrand <matti-hu@dsv.su.se>
Subject: Re: Why doesn't gethostbyaddr return a value?
Message-Id: <qum67zo94dy.fsf@cyclone.stanford.edu>
[ Posted and mailed. ]
Matti Hultstrand <matti-hu@dsv.su.se> writes:
> The problem is that gethostbyaddr doesn't return any value in my script.
> I use it like this: $hostname = gethostbyaddr($ipaddr, AF_INET); Why
> doesn't that work?
Are you sure that you can resolve those addresses? Maybe their name
resolution is broken. Can you get a name back using host or nslookup?
> Does gethostbyaddr only return host names that are within the local
> network?
Nope. Works on any IP address with reverse name lookup.
--
Russ Allbery (rra@cs.stanford.edu) <URL:http://www.eyrie.org/~eagle/>
------------------------------
Date: 8 Jan 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Jan 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.
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 V7 Issue 974
*************************************