[8547] in Perl-Users-Digest
Perl-Users Digest, Issue: 2165 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 23 15:07:59 1998
Date: Mon, 23 Mar 98 12:01:57 -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 Mon, 23 Mar 1998 Volume: 8 Number: 2165
Today's topics:
Ref to var in other sub? <david_delgreco@intuit.com>
Remove symlink <pjmone@symbioticinc.com>
Re: Splitting Arrays (Parenttime)
sprintf rounding error <kmiles@erols.com>
Re: sprintf rounding error <uri@sysarch.com>
Re: Submitting to another CGI-Script (brian d foy)
Re: Submitting to another CGI-Script (Parenttime)
Re: SybPerl for NT 4.0? mpeppler@mbay.net
Re: Sybperl return values <mpeppler@mbay.net>
Testing CGI POerl scripts offline <webmaster@portugalsystems.pt>
Re: ts: unexpected behavior of "last" with "print" (Andrew M. Langmead)
Re: Variable question (Mike Stok)
Re: Variable question <jimbo@soundimages.co.uk>
Re: Wanted: email address gleaner (John Stanley)
Re: Wanted: email address gleaner (John Stanley)
Re: What does "UNIX" stand for.. <mikk0022@maroon.tc.umn.edu>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 23 Mar 1998 11:17:53 -0800
From: David DelGreco <david_delgreco@intuit.com>
Subject: Ref to var in other sub?
Message-Id: <3516B560.CC6EED9B@intuit.com>
A little help understanding something please? Though as I write this, I
think I see where I may have gone wrong.
I'm writing a Perl app to run on a Persistent Perl on an Oracle web
server. The thing caches the bytecode as well Perl itself, making for
really quick responses. This pertains because, in caching the bytecode,
it also caches any global var's declared.
No prob, methinks, I'll just 'use strict', lexically scope everything
and all will be well.
However, in keeping with the principal of laziness, I was hoping to make
use of some formerly global hashes of hashes (now scoped in main() )
without actually passing the hashes or reference to same every time I
want to use them.
I've seen various error messages referring to, say main::myvar, and I've
seen similar syntax in Ch. 4 of the camel book, all of which gave me the
impression I could reference a var, hash, or array in another sub,
something like this:
use strict;
main();
sub main() {
my (%config);
#code to build simple hash of hashes from a config file
# a structure like
#Code1
foreach (keys %config) { print }
mysub();
}
sub mysub() {
#Code2
foreach (keys %main::config) { print }
}
Code1 executes fine and lists out all the keys I've gathered. Code2
doesn't do squat, however. Is there a way to reference main's hash
without passing it explicitly? Have I overshot my lazy ambitions and
will have to go pass some references? Or am I just demonstrating my
hazy concept of packages???
TIA!
------------
David DelGreco david_delgreco@intuit.com
Intranet Engineer and constantly increasing fan of Perl
------------------------------
Date: Mon, 23 Mar 1998 13:22:27 -0500
From: Paul Mone <pjmone@symbioticinc.com>
Subject: Remove symlink
Message-Id: <6f69bp$47j@bgtnsc03.worldnet.att.net>
PerlPeople,
I have a script that creates a symbolic link (using symlink())from a
file below the www root to /htdocs/files. I don't want this link to
stick around after the user has downloaded the file, so how can I remove
this symbolic link?
Paul
------------------------------
Date: Mon, 23 Mar 1998 13:40:06 -0500
From: "Andrew Lee (Parenttime)" <andrewf@cp.pathfinder.com>
Subject: Re: Splitting Arrays
Message-Id: <Pine.GSO.3.95.980323132144.22695D-100000@cp.pathfinder.com>
On Sun, 15 Mar 1998, Jesse Rosenberger wrote:
> Date: Sun, 15 Mar 1998 19:01:05 -0800
> From: Jesse Rosenberger <jesse@savalas.com>
> Newsgroups: comp.lang.perl.misc
> Subject: Splitting Arrays
>
> Question #1: I have a array named @arr, that has 4 numbers in
> it...numbers differ every time with a number 1-4...but they look like "4
> 3 2 1", how can I split this array into 4 seperate variables......i.e. I
> have an array: @arr = "3 4 2 1", I want $anum to equal 3, $bnum to equal
> 4, $cnum to equal 2, and $dnum to equal 1. I know it's pretty easy and
> I used to know how to do it but I seem to have forgotten after not doing
> it for a while.
$i = 0;
foreach $var (@arr) {
$myarrayval[$i++] = $var;
}
Yes??
>
> Question #2: How can you take a variable that contains a word....that
> may contain spaces...and break each letter into a seperate
> variable...the word may be any length, but will probably not contain any
> characters besides letters, and spaces (let's assume it won't) how could
> I go about doing this?
@words = split ' ', $buffer;
foreach $i (0 .. $#words) {
@chars = split //, $words[$i];
}
Point on Perl style ... arrays and hashes are powerful data structures.
It is a mistake to think that a "variable" is only of type scalar. The
power of Perl lies in its built in string manipulation AND it's built in
data types, namely arrays and hashes.
>
> Thanx in advance,
> Jesse Rosenberger
>
>
>
-------------------------------------------------------------
Andrew F. Lee | |
Software Engineer | parenttime.com |
email: andrewf@pathfinder.com | 1271 Avenue of the Americas |
Phone: (212) 522-2769 | New York, N.Y. 10020 |
-------------------------------------------------------------
When I say, "Ignore the man behind the curtain."
That is because there is no man behind the curtain.
------------------------------
Date: Mon, 23 Mar 1998 13:39:07 -0500
From: Kevin Miles <kmiles@erols.com>
Subject: sprintf rounding error
Message-Id: <3516AC4B.2A0@erols.com>
PerlFAQ says "...it probably pays not to trust whichever system rounding
is being used by Perl, but to instead implement the rounding function
you need yourself."
This rounding is so basic, I didn't think I would have to write my own
sub. Any ideas ( some round correctly, others don't )?
foreach (qw(14.85 8.25 22.55 10.17 17.51 18.05 14.98 9.51 8.02 7.92)) {
print "$_\t" . sprintf("%07.1f",$_) . "\n";
}
Output:
14.85 00014.8
8.25 00008.2
22.55 00022.6
10.17 00010.2
17.51 00017.5
18.05 00018.1
14.98 00015.0
9.51 00009.5
8.02 00008.0
7.92 00007.9
------------------------------
Date: 23 Mar 1998 14:22:14 -0500
From: Uri Guttman <uri@sysarch.com>
To: kmiles@erols.com
Subject: Re: sprintf rounding error
Message-Id: <x74t0pgql5.fsf@sysarch.com>
Kevin Miles <kmiles@erols.com> writes:
> PerlFAQ says "...it probably pays not to trust whichever system rounding
> is being used by Perl, but to instead implement the rounding function
> you need yourself."
>
> This rounding is so basic, I didn't think I would have to write my own
> sub. Any ideas ( some round correctly, others don't )?
try this loop with an extra sprintf %20.20f in it. the internal
reperesentations of some of your values is not what you think. that is
what causes the apparent round error. which is why you should implement
your own round if you want accuracy.
> foreach (qw(14.85 8.25 22.55 10.17 17.51 18.05 14.98 9.51 8.02 7.92)) {
> print "$_\t" . sprintf("%07.1f",$_) . "\n";
actually you could have save a call by doing this (with the extra format):
printf "$_\t%07.1f\t%.20f\n", $_, $_ ;
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---- 8 Years of Perl Experience, Available Immediately
uri@sysarch.com --------- Resume and Perl Example at http://www.sysarch.com
Use the Best Search Engine on the Net -------- http://www.northernlight.com
------------------------------
Date: Mon, 23 Mar 1998 13:05:31 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Submitting to another CGI-Script
Message-Id: <comdog-ya02408000R2303981305310001@news.panix.com>
Keywords: from just another new york perl hacker
In article <7xyay1xsde.fsf@beavis.vcpc.univie.ac.at>, Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at> posted:
>Re: Submitting to another CGI-Script, Webmaster
><wv@earthling.net> said:
>
>Webmaster> Hi, how can one Perl-Script submit FORM-Data to
>Webmaster> another CGI-Script (on another server)? E.g.:
>Webmaster> Submit Website-Data to multiple Searchengines.
>
>Use the LWP module family. Use CPAN from
>http://www.perl.com/ if you don't already have this.
in that family there is an abstract interface to the major search
engines - WWW::Search, which would be a lot less painful than
directly using some of the other modules there.
good luck :)
--
brian d foy <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers <URL:http://www.pm.org>
------------------------------
Date: Mon, 23 Mar 1998 13:19:11 -0500
From: "Andrew Lee (Parenttime)" <andrewf@cp.pathfinder.com>
Subject: Re: Submitting to another CGI-Script
Message-Id: <Pine.GSO.3.95.980323125925.22695C-100000@cp.pathfinder.com>
On Mon, 23 Mar 1998, Webmaster wrote:
> Date: Mon, 23 Mar 1998 16:58:42 +0100
> From: Webmaster <wv@earthling.net>
> Newsgroups: comp.lang.perl.modules, comp.lang.perl.misc, alt.perl
> Subject: Submitting to another CGI-Script
>
> Hi,
>
> how can one Perl-Script submit FORM-Data to another
> CGI-Script (on another server)?
> E.g.: Submit Website-Data to multiple Searchengines.
The operative words are "another server." THis means that you will need
to use networking protocols. I would recommend looking at Socket.pm.
Your cgi script can send a typeglob (FORM *) as a string to another
process (another cgi) via a stream socket (that is, using TCP packets).
There are plenty of examples of how to do this, the following is a an
example I have sitting around of a socket server:
#!/usr/local/bin/perl
use IO::Socket;
$PROTO="tcp";
$LOCALHOST="foo.com";
$PORT=2001;
$sock = new IO::Socket::INET( LocalHost => $LOCALHOST,
LocalPort => $PORT,
Proto => $PROTO,
Listen => 5,
Reuse => 1
);
die "Could not connect! $!" unless $sock;
while ($new_sock = $sock->accept()) {
while (defined ($buf = <$new_sock>)) {
# PARSE FORM DATA HERE
# Or do whatever ....
# if this client needs to handle
# many accepts, use fork()
}
}
close ($sock);
Sending messages to the server is easy :
#!/usr/local/bin/perl5
use IO::Socket;
$PROTO="tcp";
$PEERHOST="foo.com";
$PEERPORT=2001;
$sock = new IO::Socket::INET( PeerHost => $LOCALHOST,
PeerPort => $PORT,
Proto => $PROTO
);
die "Could not connect! $!" unless $sock;
if($RAW_FORM_DATA) {
print $sock "CGI REQUEST: $RAW_FORM_DATA\n";
# for a POST operation, send a string of key, value pairs
# with GET, just use the untranslated url
}
close ($sock);
Hope this helps. I guess there are ways to do this without sockets, but
for two processes on seperate boxes, this is the standard way of
communicating (right out of BSD 4.3 (?))
>
>
> Thanks in advance
>
> Walter Voell
>
>
-------------------------------------------------------------
Andrew F. Lee | |
Software Engineer | parenttime.com |
email: andrewf@pathfinder.com | 1271 Avenue of the Americas |
Phone: (212) 522-2769 | New York, N.Y. 10020 |
-------------------------------------------------------------
When I say, "Ignore the man behind the curtain."
That is because there is no man behind the curtain.
------------------------------
Date: Mon, 23 Mar 1998 12:39:18 -0600
From: mpeppler@mbay.net
Subject: Re: SybPerl for NT 4.0?
Message-Id: <6f6a4m$h4b$1@nnrp1.dejanews.com>
In article <3513f204.104140446@cmnews.capmark.funb.com>,
bob.rizzo@funb.com (Robert Rizzo) wrote:
>
>
> Does SybPerl exist on NT 4.0?
Yes, the latest version (2.09) builds on NT.
Michael
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Mon, 23 Mar 1998 10:07:09 -0800
From: Michael Peppler <mpeppler@mbay.net>
Subject: Re: Sybperl return values
Message-Id: <3516A4CD.1D6F@mbay.net>
Gary Udstrand wrote:
>
> Could someone please tell me how I would determine the number of
> rows updated via a sybperl call? This is perl 4.xx.
&DBCOUNT($dbproc);
>
> Also, where can I find what subroutines are available via the
> Sybperl package?
See the sybperl man page.
Michael
--
Michael Peppler -||- Data Migrations Inc.
mpeppler@datamig.com -||- http://www.mbay.net/~mpeppler
Int. Sybase User Group -||- http://www.isug.com
------------------------------
Date: Mon, 23 Mar 1998 17:56:11 -0000
From: "PORTUGAL SYSTEMS" <webmaster@portugalsystems.pt>
Subject: Testing CGI POerl scripts offline
Message-Id: <6f67ms$l34$1@duke.telepac.pt>
Thanks for your attention.
I would like to know if someone knows a way (software) to test CGI Perl
Scripts without make connetion to the Net.
I've not a Server but a Virtual Host in a National ISP. Internally I use
OmniHttp Server in Windows95 and I can test some CGI Perl scripts, but if
the script has a internal call of the server path ( ex. /online/web/path to
the script/ ) I can4t test it.
Thanks for your support and anwers...
J.Oliveira
------------------------------
Date: Mon, 23 Mar 1998 19:04:13 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: ts: unexpected behavior of "last" with "print"
Message-Id: <EqACz1.5xw@world.std.com>
tsatan@hotmail.com writes:
> print "root's pw is $1\n", last if /^root:([^:]*)/;
print is a list operator, so all the arguments get evaluated
first. When the last gets evaluated the loop exits. Since the loop
exits, the print never executes.
You could fix this by fixing the precedence with parens, using the low
precedence "and" operator to combine the two terms. (which will work
almost identically unless the print() fails), or by making the print
and the last two separate statements and using in if BLOCK, or do
BLOCK with if modifier.
print("root's pw is $1\n"),last if /^root:([^:]*)/;
print "root's pw is $1\n" and last if /^root:([^:]*)/;
if(/^root:([^:]*)/) {
print("root's pw is $1\n");
last;
}
do {print "root's pw is $1\n";last} if /^root:([^:]*)/;
If you are using the statement modifer to avoid the overhead entering
a block, then look toward the first two. If you are looking to save
keystrokes, then the first two tie with two extra chars. If you are
looking for aesthetics, then take your pick, but I personally lean
towards the third, then the second then the fourth.
--
Andrew Langmead
------------------------------
Date: 23 Mar 1998 18:08:51 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Variable question
Message-Id: <6f68fj$6db@news-central.tiac.net>
In article <uyay1iayl.fsf@soundimages.co.uk>,
Jim Brewer <jimbo@soundimages.co.uk> wrote:
>> ($door, $number) = split;
>wouldn't you want to use chomp($number) to remove the newline hanging on
>the end of the 'number'?
>But most of all, the 'Until you start thinking...' part has been a real
>shift of perception treat. Thanks.
>Jim Brewer
I'll admit it, I'm not Tom, but you should check the docs for split which
explain why this happens:
DB<1> $_ = "foo bar\n"; @l = split
DB<2> X l
@l = (
0 'foo'
1 'bar'
)
and why it's different from
DB<3> $_ = "foo bar\n"; @l = split / /
DB<4> X l
@l = (
0 'foo'
1 'bar
'
)
The DB<xxx> is the debugger prompt, perl -de 1 is a useful way of checking
things out from the command line.
Many of perl's default behaviours can be understood when you think about
using it to crunch text files and what might be useful behaviour &
shorthand.
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@colltech.com | Collective Technologies (work)
------------------------------
Date: 23 Mar 1998 19:54:42 +0000
From: Jim Brewer <jimbo@soundimages.co.uk>
Subject: Re: Variable question
Message-Id: <u4t0prxml.fsf@soundimages.co.uk>
mike@stok.co.uk (Mike Stok) writes:
> I'll admit it, I'm not Tom, but you should check the docs for split which
> explain why this happens:
>
> DB<1> $_ = "foo bar\n"; @l = split
>
> DB<2> X l
> @l = (
> 0 'foo'
> 1 'bar'
> )
>
> and why it's different from
>
> DB<3> $_ = "foo bar\n"; @l = split / /
>
> DB<4> X l
> @l = (
> 0 'foo'
> 1 'bar
> '
> )
>
> The DB<xxx> is the debugger prompt, perl -de 1 is a useful way of checking
> things out from the command line.
>
> Many of perl's default behaviours can be understood when you think about
> using it to crunch text files and what might be useful behaviour &
> shorthand.
>
Dear Mike,
WOW! Perfectly obvious when you point it out. All whitespace becomes the split /PATTERN/ PATTERN default when explicitly excluded. Yes, it was right in the Camel book, which I read before I posted and, regardless, missed the point. Thanks. In addition, the perl debugger example was another real perceptual shift. In the same league as the previous shift. Thanks for that. I tried it out line by line and learnt more in those four lines than I had in the previous week!
Sincerely,
Jim Brewer
------------------------------
Date: 23 Mar 1998 19:17:35 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: Wanted: email address gleaner
Message-Id: <6f6cgf$p09$1@news.orst.edu>
In article <35163290.36B0@glpbooks.BADMAIL.com>,
Jeff Potter <jp@glpbooks.BADMAIL.com> wrote:
>John Stanley wrote:
>[]
>> >I've had requests to reprint my NG posts in magazines.
>>
>> Goody for you. You are free to reprint what you have written. This is
>> completely irrelevant to your desire to spam.
>[]
>> >nor have I felt like complaining when I've been approached similarly.
>>
>> Goody for you.
>
>You misread. I wasn't the one doing the reprinting.
I read it just fine. I didn't say you were doing the printing, but that
you are free to reprint it, whether by your own hands or through someone
else. Your copyright, your choice.
>I've had magazines send
>me email asking to reprint my posts. I've given my permission happily.
I'm very glad for you. I think I said that already.
>Was that spam I received?
I don't know. You haven't provided enough information.
>I had no idea they were going to send it;
>they are a commercial outfit. So it was unsolicited commercial email.
Yes, it was.
>Should mags and other media or whoever never contact the authors
>of posts they read for reprint or commercial purposes
>IN REGARDS TO A POST THEY READ?
I don't know. Should they? We weren't talking about "never", we were
talking about a specific spam you were intending on sending.
>Or even if the contact is
>not about a post: what if someone read your vague
>antispam posts here and wrote you *unsoliticed commercial
>email* wanting to hire you as a propagandist? Is all that spam?
One email is not spam. You were talking about sending hundreds or
thousands. (If it were just ten, you wouldn't need automation, would
you?)
------------------------------
Date: 23 Mar 1998 19:50:07 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: Wanted: email address gleaner
Message-Id: <6f6edf$cp8$1@news.orst.edu>
In article <3516318C.4835@glpbooks.BADMAIL.com>,
Jeff Potter <jp@glpbooks.BADMAIL.com> wrote:
>Actually, I don't mind the tone. I'm just looking for the facts.
>So far Stanley has seemed to be wrong, has omitted pertinent
>facts.
What "pertinent facts" have I omitted? It seems that you have the horse
at the wrong end of the cart -- you want answers, you need to provide
the facts to base those answers on. You want to know if what you are
doing is spam, you need to provide facts. You want to know if what
someone else sent you is spam, you need to provide facts.
>See my last post above if it ain't all too boring for you yet.
"My last post above" is a pretty meaningless statement. Articles have
message id's, they don't have "above" and "below". "Above" this post
right now is the top of the monitor. What is the message id of the
article you want us to refer to? Is it the one where you keep asking if
mail you got was spam but you refused to provide enough facts to answer
the question?
>I'm willing to be convinced that my project is spammish,
No, I don't think you are. You have been fighting tooth and nail to
get the answer you want. You appear to think that the "value" of your
mail somehow means it isn't really spam. It doesn't matter if the
value is in telling the world that Christ died to save us all or that
Great Lakes Press wants to sell a book of restaurant listings. The
"value" the sender puts on the message is irrelevant.
You seem to be confused by the fact that YOU didn't complain when you
got some unsolicited commercial email so it must be ok to send it. You
seem hell bent to ignore that you want to send it to hundreds or
thousands of people based on the fact that they once posted to a
newsgroup. That is quintissential spam.
>but they haven't done it yet.
How's this for a fact, Jeff? Here's a section from the DataRealm
commercial services contract:
]Client may not send out any unsolicited commercial e-mail (spam)
]related to their site or from their account at DataRealm. Violation of
]this prohibition may lead to immediate account removal.
This doesn't specify bulk, it says "any". As in, one. If you want a
definition of spam, you already have it. If you want to see if DataRealm
will pull your business' account, go ahead and spam.
------------------------------
Date: 23 Mar 1998 11:51:12 -0600
From: Chris Mikkelson <mikk0022@maroon.tc.umn.edu>
Subject: Re: What does "UNIX" stand for..
Message-Id: <87g1k9qorz.fsf@x115-105.reshalls.umn.edu>
"Phlip" <tegan@deltanet.com> writes:
> M.Ranganathan wrote:
> >On the other hand Windows has the well-deserved nick name of "Windoze".
> >Recently, I lost a whole directory (I kid you not) merely by assuming
> >my Windows NT box died (when it was merely dozing) and turning it off.
> >( Incidentally does anybody know what the deuce it is doing when it is
> >playing possum like that? )
>
> Running a screen saver?
Just taking up space?
------------------------------
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 2165
**************************************