[13998] in Perl-Users-Digest
Perl-Users Digest, Issue: 1408 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 17 12:11:32 1999
Date: Wed, 17 Nov 1999 09:10:19 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <942858619-v9-i1408@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 17 Nov 1999 Volume: 9 Number: 1408
Today's topics:
Perl and Socket <harinirayadurgam@hotmail.com>
Re: Perl and Socket (Kragen Sitaker)
Re: Perl and Socket <harinirayadurgam@hotmail.com>
Re: Perl and Socket <jtolley@bellatlantic.net>
Re: Perl and Socket (Kragen Sitaker)
Perl bug??? help me!!! <nightwolf@inea.com.ar>
Re: Perl bug??? help me!!! <gellyfish@gellyfish.com>
Problem: Forwarding arguments to a prototyped subroutin <Christian.Sarrasin@SPAMFREEubs.com>
Re: Problem: Forwarding arguments to a prototyped subro (Kragen Sitaker)
Re: qn about Getopt::Long module <linberg@literacy.upenn.edu>
Re: Script Effiency (Kragen Sitaker)
Re: seeking seek algorithm paul_p_francis@my-deja.com
Re: seeking seek algorithm (Kragen Sitaker)
Re: sort defaults to? (Kragen Sitaker)
Re: sort defaults to? (Bart Lateur)
Re: stuck man ...please help (Kragen Sitaker)
Re: thanks all (Kragen Sitaker)
Re: Tracking Form Submissions? (Kragen Sitaker)
Re: Trying to use a variable as an operator (Kragen Sitaker)
Re: Trying to use a variable as an operator (Kragen Sitaker)
Re: Trying to use a variable as an operator <jeb@burkby.com>
Re: Unload/reload modules? (M.J.T. Guy)
Re: Use sort function with reference to subroutine? <rick.delaney@home.com>
Re: Use sort function with reference to subroutine? (Andrew Johnson)
Re: Use sort function with reference to subroutine? <thelma@alpha2.csd.uwm.edu>
Re: Use sort function with reference to subroutine? (Sean McAfee)
Re: Use sort function with reference to subroutine? <thelma@alpha2.csd.uwm.edu>
Using Apache::AuthenDBI <webmaster@webdream.com>
Re: Using Apache::AuthenDBI <craig@mathworks.com>
Re: Wierd List Behavior <sariq@texas.net>
Re: Wierd List Behavior <sariq@texas.net>
Re: Wierd List Behavior (Kragen Sitaker)
Re: Wierd List Behavior <sariq@texas.net>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 17 Nov 1999 14:07:14 -0000
From: "Harini" <harinirayadurgam@hotmail.com>
Subject: Perl and Socket
Message-Id: <80ud0o$b6n$1@nclient15-gui.server.virgin.net>
I'm a Perl novice. Though I've seen quite a few examples in Perl, I could
not figure out how to connect to a socket and send a string to it from a
client. I'm using MS-DOS.. I was able to make a server listen, and client
connect to it, but could not send a string. Could someone give me a piece of
code for the client and server or point me in the right direction
Thanx
Regards
Harini
------------------------------
Date: Wed, 17 Nov 1999 15:16:36 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Perl and Socket
Message-Id: <oFzY3.21364$YI2.961892@typ11.nn.bcandid.com>
In article <80ud0o$b6n$1@nclient15-gui.server.virgin.net>,
Harini <harinirayadurgam@hotmail.com> wrote:
>I'm a Perl novice. Though I've seen quite a few examples in Perl, I could
>not figure out how to connect to a socket and send a string to it from a
>client. I'm using MS-DOS.. I was able to make a server listen, and client
>connect to it, but could not send a string. Could someone give me a piece of
>code for the client and server or point me in the right direction
print SOCKET $string;
# and maybe you want to autoflush the socket. Keep your pipes piping hot.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Wed, 17 Nov 1999 15:29:00 -0000
From: "Harini" <harinirayadurgam@hotmail.com>
Subject: Re: Perl and Socket
Message-Id: <80uhq0$cdu$1@nclient15-gui.server.virgin.net>
Thanx. Now how do I receive it at the server ??
Kragen Sitaker <kragen@dnaco.net> wrote in message
news:oFzY3.21364$YI2.961892@typ11.nn.bcandid.com...
> In article <80ud0o$b6n$1@nclient15-gui.server.virgin.net>,
> Harini <harinirayadurgam@hotmail.com> wrote:
> >I'm a Perl novice. Though I've seen quite a few examples in Perl, I could
> >not figure out how to connect to a socket and send a string to it from a
> >client. I'm using MS-DOS.. I was able to make a server listen, and client
> >connect to it, but could not send a string. Could someone give me a piece
of
> >code for the client and server or point me in the right direction
>
> print SOCKET $string;
> # and maybe you want to autoflush the socket. Keep your pipes piping hot.
> --
> <kragen@pobox.com> Kragen Sitaker
<http://www.pobox.com/~kragen/>
> The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
> <URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Wed, 17 Nov 1999 15:35:57 GMT
From: James Tolley <jtolley@bellatlantic.net>
Subject: Re: Perl and Socket
Message-Id: <38283EEC.1277A69C@bellatlantic.net>
Harini wrote:
>
> I could
> not figure out how to connect to a socket and send a string to it from a
> client.
You should really try to post some code to narrow down the question a
little.
Here's some code which will do what you want from win95. If you want to
use Socket instead of IO::Socket, post some code and I'm sure you'll get
a response.
hth,
James
##################
$| = 1;
use IO::Socket;
print "usage: sock.pl <www.host.org/path/resource.ext>" and exit unless
@ARGV;
$ARGV[0] =~ /^(?:http:\/\/)?([^\/]+)\/?(.*)$/;
my $http_host = $1;
my $host = $http_host.":80";
my $resource = $2 || '';
print qq{Getting:
host: $host
resource: /$resource
};
my $q = '';
my $socket = new IO::Socket::INET
PeerAddr => $host;
Proto => 'tcp',
Type => SOCK_STREAM;
die "no socket: $!" unless $socket;
my $request = qq{GET /$resource HTTP/1.1
host: $http_host
};
print $socket $request;
print qq{Here's the request:<<EOF;
$request};
print "EOF\n...and here's the response:\n\n";
print, $q = <STDIN> while (<$socket>); # pause after each line
------------------------------
Date: Wed, 17 Nov 1999 15:34:13 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Perl and Socket
Message-Id: <VVzY3.21417$YI2.960120@typ11.nn.bcandid.com>
In article <80uhq0$cdu$1@nclient15-gui.server.virgin.net>,
Harini <harinirayadurgam@hotmail.com> wrote:
>Thanx. Now how do I receive it at the server ??
read SOCKET, $string, $maxsize -- or, if it's terminated by \n, <SOCKET>.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Wed, 17 Nov 1999 13:53:23 -0500
From: Diego Fernandez <nightwolf@inea.com.ar>
Subject: Perl bug??? help me!!!
Message-Id: <3832F9A3.792957B@inea.com.ar>
Try this :
print ("Bug" == "B");
it returns 1 !!!! True!
What is wrong?!
I need to look for a value in an array using grep but is behavior makes
my program fail because I use :
if (grep(/Value/, @list) { ....
and Value match with Value1 ... Value2.
so I try if (grep { $_ == "Value"} @list) but it fails too.
Thanks for your help.
Diego.
------------------------------
Date: 17 Nov 1999 16:57:49 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Perl bug??? help me!!!
Message-Id: <3832de8d_1@newsread3.dircon.co.uk>
Diego Fernandez <nightwolf@inea.com.ar> wrote:
> Try this :
>
> print ("Bug" == "B");
>
> it returns 1 !!!! True!
>
> What is wrong?!
What does it say if you run this with Perls -w switch ?????
/J\
--
"Mr Creutzfeldt and Mr Jakob: No-one had ever heard of these two eminent
medical men until someone had the
------------------------------
Date: Wed, 17 Nov 1999 16:08:48 +0100
From: Christian Sarrasin <Christian.Sarrasin@SPAMFREEubs.com>
Subject: Problem: Forwarding arguments to a prototyped subroutine
Message-Id: <3832C500.79A265B0@SPAMFREEubs.com>
I'm trying to forward a subroutine's arguments to another one (while slightly
tempering with them). This apparently works fine as long as you're not using
function prototypes. However, it seems to not work in a consistent fashion when
using function prototypes.
Consider the following little Perl proggie:
sub mysub2($$$;$) {
my $count = 0;
foreach (@_) {
print $count++ ." : $_\n";
}
}
sub mysub1($$;$) {
mysub2(1, (@_));
}
mysub1("abc", "xyz");
What this is supposed to do is simply add a '1' argument in front of the
arguments passed to mysub1() and forward these to mysub2(). If I run this
program, I get:
Not enough arguments for main::mysub2 at testsub.pl line 9, near "))"
Execution of testsub.pl aborted due to compilation errors.
Which is not correct since (at runtime), I have indeed three actual parameters
for mysub2(), namely 1, "abc" and "xyz" - as getting rid of mysub2's prototype
would show.
What's even weirder is that if put mysub1($$;$) before mysub2($$$;$), the
program runs like a charm!
The reason I have the parentheses around @_ when calling mysub2() is that I
thought this could help force a list context in the assignment of mysub2's
actual parameters (I thought otherwise, mysub2's $_[1] could get the length of
mysub1's @_ since I would be assigning an array in a scalar context. But this
doesn't seem to help...
Could it be that checks of adherance to prototypes should rather be done at
runtime, not at compiletime? But even with the checks as they are, it's kind of
weird that the supposed non-conformance is flagged only in certain cases.
Does anybody know if that's a bug in Perl (or my version of Perl - see version
info below)? But most likely, I am just missing something...
Thanks,
Christian.
--------
perl -v
This is perl, version 5.005_03 built for MSWin32-x86-object
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-1999, Larry Wall
Binary build 520 provided by ActiveState Tool Corp. http://www.ActiveState.com
Built 17:55:54 Sep 28 1999
------------------------------
Date: Wed, 17 Nov 1999 15:38:28 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Problem: Forwarding arguments to a prototyped subroutine
Message-Id: <UZzY3.21471$YI2.964386@typ11.nn.bcandid.com>
In article <3832C500.79A265B0@SPAMFREEubs.com>,
Christian Sarrasin <Christian.Sarrasin@SPAMFREEubs.com> wrote:
>Consider the following little Perl proggie:
>
>sub mysub2($$$;$) {
> my $count = 0;
> foreach (@_) {
> print $count++ ." : $_\n";
> }
>}
>
>sub mysub1($$;$) {
> mysub2(1, (@_));
>}
unshift @_, 1;
&mysub2; # or goto &mysub2 in extreme cases
>What's even weirder is that if put mysub1($$;$) before mysub2($$$;$), the
>program runs like a charm!
That's because mysub2's prototype isn't visible to mysub1.
>Could it be that checks of adherance to prototypes should rather be done at
>runtime, not at compiletime? But even with the checks as they are, it's kind of
>weird that the supposed non-conformance is flagged only in certain cases.
Prototypes are there to help you screw with Perl's parsing, not to
check for adherence.
If you don't want to screw with Perl's parsing, DON'T USE PROTOTYPES.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: 17 Nov 1999 11:10:15 -0500
From: Steve Linberg <linberg@literacy.upenn.edu>
Subject: Re: qn about Getopt::Long module
Message-Id: <m37ljh85g8.fsf@projdirc.literacy.upenn.edu>
mgjv@comdyn.com.au (Martien Verbruggen) writes:
> On 16 Nov 1999 16:57:31 -0500,
> Steve Linberg <linberg@literacy.upenn.edu> wrote:
> > According to 'perldoc Getopt::Long', it will die if called with invalid
> > options, unless of course you call it in an eval block, where you can check
> > for errors in the usual fashion. But it's all in the documentation.
>
> I can't really find that die bit in the documentation, and my
> experience with it is different. Let's test it:
You're right, I misread the documentation. It dies if there is an error in
the configuration or option definitions, not in the options as they are
processed. (I use Getopt::Std most of the time.) Here's what it says:
---------------------------------------------------------------------------
Return values and Errors
Configuration errors and errors in the option definitions are
signalled using die() and will terminate the calling
program unless the call to Getopt::Long::GetOptions() was embedded
in eval { ... } or die() was trapped using $SIG{__DIE__}.
---------------------------------------------------------------------------
Seems clear now, but yesterday, to a tired brain doing a quick scan, it
didn't sink in. Moral: don't post to clpm without a decent amount of
caffeine in your bloodstream, it could be hazardous.
--
Steve Linberg, Chief Goblin
Silicon Goblin Technologies
http://silicongoblin.com
Be kind. Remember, everyone you meet is fighting a hard battle.
------------------------------
Date: Wed, 17 Nov 1999 14:11:24 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Script Effiency
Message-Id: <gIyY3.21304$YI2.953898@typ11.nn.bcandid.com>
In article <B45791A4.984%rgrnbrg@xmission.com>,
Ryan Greenberg <rgrnbrg@xmission.com> wrote:
> I'm fairly new to this group, and I only started working with Perl about
>two weeks ago. I finally put together my first script using the Perl Black
>Book reference guide I bought. Although the script does what I want, is
>there a resource I can consult to see if I am using awkward methods to
>acomplish my goal?
CGI is a bit on the fat side; you might want to run the script another
way if you're concerned about efficiency. The time to recompile your
script for every hit probably drowns any time it takes to run it.
Uri did a good job of pointing out things you were doing that were a
little awkward, although his comments were perhaps a bit harsh in
tone. He didn't mention that using CGI.pm might make some of those
things easier, like printing the HTML <head>.
Oh, this:
> print "<TR><TD>$individual[1] $individual[0]</TD>";
> print "<TD>$individual[2]</TD>";
> print "<TD>$individual[3]</TD>";
> print "<TD><A
>HREF=\"mailto:@individual[4]\">$individual[4]</A></TD></TR>\n";
could be rewritten as
print '<tr>', map {'<td>', $_, '</td>'}
"@individual[1,0]",
@individual[2,3],
qq(<a href="mailto:$individual[4]">$individual[4]</a>);
print "</tr>\n";
I think that would be a little easier to read, but maybe that's just me.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Wed, 17 Nov 1999 14:49:06 GMT
From: paul_p_francis@my-deja.com
Subject: Re: seeking seek algorithm
Message-Id: <80uf91$tgq$1@nnrp1.deja.com>
hello Kragen et all,
thanks for the response. i made a typing mistake, the file size is 70g
not 20G. its created by a Stratus/VOS mainframe. i work in a data ware
house group that is +4Tera. the server is Sun E5000 with 8G mem and 16
CPU's. the bottleneck seems to be IO because top and vmstat seem to
support this. im new to perl and would like to learn how to do this in
perl if possible.
using threads in C, i have sucessfully opened 4 read/bin file handles
to this file and agregated the values im interested in (havent started
the freq_dist though). the performance increase in C between
synchronous and asynchronous is 37% faster. since the perl 5.005
compiler seems to be using cc calls, i am interested in learning how to
do this in perl especially for the freq_dist.
thanks,
--paul
In article <jQgY3.18856$YI2.801688@typ11.nn.bcandid.com>,
kragen@dnaco.net (Kragen Sitaker) wrote:
> In article <80qpfg$9rt$1@nnrp1.deja.com>, <paul_p_francis@my-
deja.com> wrote:
> >i have a large (over 20 Gig) binary file with fixed length records. i
> >have to aggregate 2 fields and calculate frequency distribution on
> >another field. the problem is it takes over 65 minutes for my perl
> >script to complete on a unix server running perl 5.005.
>
> What's the bottleneck on your system? Is it the disk speed, the CPU
> speed, or what? 20 gig over 65 minutes is
> 20*1024/(65*60) =
> 5.25128205128205128205 megabytes per second. If you have a relatively
> slow disk, this might be the bottleneck.
>
> You can test it; just read in the whole file and don't bother to do
> anything on it. One-megabyte chunks should be sufficient to make the
> CPU overhead disappear.
>
> Also, you can run 'top' while you're running your current script to
see
> what the CPU usage is. If it's 30%, it probably means your CPU is not
> the bottleneck. If it's 100% (including system time and other
> processes --- i.e. 0% idle) then the CPU is the bottleneck.
>
> If the CPU is not the bottleneck, consider getting a RAID, or just a
> faster disk.
>
> >if possible, i am hoping to find a way to speed this up.
> >
> >currently i am trying to use threads and seek() to start at 4
> >different places (tot_recs/4)in the file and work forward until
overlap-
> >1 with no luck so far.
>
> This may work if (a) you have multiple CPUs and (b) the CPU is the
> bottleneck. Some advice in this case:
> - use multiple processes, not threads, if you can help it; they're
easier.
> - test to see if it speeds things up.
>
> What's the "no luck" part, btw? Are you having trouble seek()ing in a
> large file?
>
> >if anyone has a better approach or a related example, i would really
> >appreciate it.
>
> Is it possible to do this incrementally? For example, if your file is
> 20Gig, but the only way it changes is that 100MB gets added at the end
> every day, you could perhaps win by scanning only that 100MB and
> updating your stats. If it's updated in the middle, perhaps you could
> get the updated record numbers logged somewhere, along with their
> previous contents.
>
> --
> <kragen@pobox.com> Kragen Sitaker
<http://www.pobox.com/~kragen/>
> The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
> <URL:http://www.pobox.com/~kragen/bubble.html>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 17 Nov 1999 15:24:21 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: seeking seek algorithm
Message-Id: <FMzY3.21400$YI2.962669@typ11.nn.bcandid.com>
In article <80uf91$tgq$1@nnrp1.deja.com>, <paul_p_francis@my-deja.com> wrote:
>thanks for the response. i made a typing mistake, the file size is 70g
>not 20G.
Wow, that's a lot of data. So you're actually getting a pretty decent
data rate off the disk, better than 15 megabytes/sec. But . . . you
must be using a RAID already then, right?
> its created by a Stratus/VOS mainframe.
How does it get onto your disk? Perhaps you could do your stats when
you're transferring it to the disk; then your I/O will be free.
> i work in a data ware
>house group that is +4Tera. the server is Sun E5000 with 8G mem and 16
>CPU's. the bottleneck seems to be IO because top and vmstat seem to
>support this.
Well, if the bottleneck really is I/O, then the way to speed it up is
to buy faster I/O hardware -- RAID, or faster disks, or 70G of RAM.
>im new to perl and would like to learn how to do this in
>perl if possible.
I don't know how good Perl's large-file support on UltraSPARC is. Can
you seek ok?
>using threads in C, i have sucessfully opened 4 read/bin file handles
>to this file and agregated the values im interested in (havent started
>the freq_dist though). the performance increase in C between
>synchronous and asynchronous is 37% faster.
That sort of suggests that maybe the bottleneck isn't I/O -- if it
were, the increased disk seeking should have slowed you down. But I've
never worked with >10G datasets, so I don't know.
>since the perl 5.005
>compiler seems to be using cc calls, i am interested in learning how to
>do this in perl especially for the freq_dist.
You may or may not find it's slower in Perl. If the bottleneck is I/O,
it might not be. But if the bottleneck is CPU, it probably will be.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Wed, 17 Nov 1999 14:24:37 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: sort defaults to?
Message-Id: <FUyY3.21315$YI2.955390@typ11.nn.bcandid.com>
In article <3832A02A.23FDA124@mail.ford.com>,
Richard H <rhardicr@mail.ford.com> wrote:
>to sort, but if I just use :
>for (sort {$a <=> $b} keys %allrows) {
>
>the numbers are sorted but the text keys are not,
>will this sort impose any order to the entries keyed with text
No. But it will scramble them.
>or does <=> evaluate them all to 1 ?
0. And you'll get a warning with -w.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Wed, 17 Nov 1999 16:32:39 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: sort defaults to?
Message-Id: <3832d61d.759502@news.skynet.be>
Richard H wrote:
> if I just use :
>
>for (sort {$a <=> $b} keys %allrows) {
> print "$_ : @{ $allrows{$_} } \n";
>}
>
>the numbers are sorted but the text keys are not,
Text that cannot be converted, even partially, to a number, will be
treated as zero. If you're using "-w", which you should, you'd get a lot
of warnings genre 'argument "foo" is not numeric in comparison'.
>will this sort impose any order to the entries keyed with text
>or does <=> evaluate them all to 1 ?
>or do the text one not get sorted at all now?
If the sort sub returns 0, which is what happens if you do { "a" <=> "b"
} (both are zero), then your guess is as good as mine. The sort
subroutine will pick any order it damn well chooses, which is the one
that is easiest for the used sorting algorythm, but most of the time NOT
in the original order. Actually, the order looks pretty random.
What I think you should be doing, is separating the numbers from the
text, sort each list independently, and then output one after the other.
Or maybe the Schwartzian Transform may help, to avoid test if a value is
a number, every time.
You can use a regex to see if a value looks like a number. This one will
do for most cases, provided the number doesn't have an exponential part
(which happens if the value is very big or very small):
/^-?\d+\.?\d*$/
--
Bart.
------------------------------
Date: Wed, 17 Nov 1999 14:18:43 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: stuck man ...please help
Message-Id: <7PyY3.21309$YI2.954702@typ11.nn.bcandid.com>
In article <80v38t$bge$1@news.vsnl.net.in>,
Ishpal <ishpal@infobase.co.in> wrote:
>I'm trying to invoke perl script from the newly installed apache webserver
>but with no results.It gives an interal server error.
>How can I make the server execute the perl scripts.
>I'm a new user and havent worked with perl on apache.I've worked with perl
>on win-nt/sambar server
See perlfaq9, question 1. Or the Idiot's Guide to Solving Perl/CGI Problems.
>Help is urgently reqd.
If it is urgent, do us a favor and don't post to usenet.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Wed, 17 Nov 1999 14:22:23 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: thanks all
Message-Id: <zSyY3.21311$YI2.955060@typ11.nn.bcandid.com>
In article <80u61v$n9j$1@nnrp1.deja.com>, <muhudin@my-deja.com> wrote:
>> With that mentality I'd rather not have you as a fellow programmer
>
>what mentality? Is asking help such a bad idea?? I think this newsgoup
>is helping each other out.
The mentality of wanting other people to do your homework for you.
>I do not like your patronizing attitude quite frankly..
Well, that's fine. We don't like yours either :)
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Wed, 17 Nov 1999 15:14:08 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Tracking Form Submissions?
Message-Id: <4DzY3.21360$YI2.959469@typ11.nn.bcandid.com>
In article <38324244.CBAAE999@cris.com>, Kevin J. Bennett <tdk@cris.com> wrote:
>I have a standard HTML form that collects data and submits to another
>site other
>than mine? Is there anyway through an HTML tag or CGI script to log the
>submissions on my machine and pass the data on to the desired host at
>the same time transparent to the user through the one submit button?
You could submit to a CGI script on your machine, which would use LWP
to submit the form to the other machine and fetch the results. Or, if
it's a GET form, you could use a redirect. But it's not really a Perl
question.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Wed, 17 Nov 1999 14:57:12 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Trying to use a variable as an operator
Message-Id: <cnzY3.21345$YI2.959667@typ11.nn.bcandid.com>
In article <38328215.D08A6D61@burkby.com>, Joe Burpee <jeb@burkby.com> wrote:
>BTW, one thing missing from your reduce seems to be the handling of the
>empty-list case, which for many APL primitives would return the identity
>element. These can be useful for consistency in some expressions. I
>guess you could trap an undef $a in the &$code block.
Obviously this is the correct thing to do when it is possible. But
being given an arbitrary code block makes it difficult for reduce to
deduce the identity element, if there is one. (I think you're
suggesting calling the &$code block and having it detect that it's
being called with undef arguments, and having it return its identity
element. This is probably not optimal from a readability and efficiency
standpoint.)
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Wed, 17 Nov 1999 15:10:50 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Trying to use a variable as an operator
Message-Id: <_zzY3.21355$YI2.960985@typ11.nn.bcandid.com>
In article <80tpir$rbh$1@monet.op.net>, Mark-Jason Dominus <mjd@op.net> wrote:
>Yeah. Someday I'm going to write APL.pm. Then the world will
>tremble.
I don't know about the world, but *I* will tremble. :)
> sub reduce (&$@) {
> my $code = shift;
> local $a = shift;
>
> for (@_) {
> local $b = $_;
> $a = &$code;
> }
>
> $a;
> }
I think I like this a little better than mine.
> @list1 = (1,2,3,4,5);
> @list2 = (2,3,5,7,11);
> @result = combine { $a + $b } @list1, @list2;
>
>[[@result]] is [[(3,5,8,11,16)]]
>
> sub combine (&\@\@) {
> my ($code, $ar1, $ar2) = @_;
> my @result;
>
> while (@$ar1 && @$ar2) {
> local $a = shift @$ar1;
> local $b = shift @$ar2;
> push @result, &$code;
> }
>
> @result;
> }
Hmm, what do you do when the arrays aren't conformable?
Here's another way to do it:
@result = map { $list1[$_] + $list2[$_] } 0..$#list1;
That's not quite as comfy to put in a sub:
#!/usr/bin/perl -w
use strict;
sub combine (&\@\@) {
my ($code, $ar1, $ar2) = @_;
return map {
local ($a, $b) = ($ar1->[$_], $ar2->[$_]);
&$code
} 0..$#$ar1;
}
my @list1 = qw(1 2 3 4 5);
my @list2 = qw(2 3 5 7 11);
print "@{[combine {$a + $b} @list1, @list2]}\n"
(I've followed you with local() here. In general I don't like dynamic
scoping, but I guess it's worth it here, for readability and consistency
with sort.)
>Yeah. It's funny that Iverson didn't think of it. Oh, I know why
>not. You need a spaceship operator for it to be useful. (Note for
>APL folks: In Perl, the <=> (`spaceship') operator returns a negative
>value if its left operand is numerically less than its right operand,
>positive if vice vera, and 0 if they are equal.)
>
>I was thinking that if you had a generic `grade' operator, you would
>say
>
> grade > VECTOR
>
>to get the effect of grade-up. But of course > doesn't yield enough
>information.
It depends on your sorting algorithm, I think. You can treat
not-greater-than as less-than, but I think some sorting algorithms will
get upset if a < b and b < a, or if a < a, or if a < b, b < c, and c < a.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Wed, 17 Nov 1999 17:02:52 GMT
From: Joe Burpee <jeb@burkby.com>
Subject: Re: Trying to use a variable as an operator
Message-Id: <3832DFD6.8458EF@burkby.com>
Kragen Sitaker wrote:
>
> Joe Burpee wrote:
> >BTW, one thing missing from your reduce seems to be the handling of the
> >empty-list case, which for many APL primitives would return the identity
> >element. These can be useful for consistency in some expressions. I
> >guess you could trap an undef $a in the &$code block.
>
> Obviously this is the correct thing to do when it is possible. But
> being given an arbitrary code block makes it difficult for reduce to
> deduce the identity element, if there is one. (I think you're
> suggesting calling the &$code block and having it detect that it's
> being called with undef arguments, and having it return its identity
> element. This is probably not optimal from a readability and efficiency
> standpoint.)
Right, that was what I was thinking of, and the phrase "not optimal" is
probably far too kind. I really didn't know how to do it elegantly, and
was hoping maybe you knew. ;-)
At any rate the fact that it is doable at all in Perl suggests an
interesting potential advantage over APL. As you're probably aware, in
APL (but not in J) a user-defined function can be dyadic, monadic, or
niladic -- 2, 1, or 0 args respectively. An ambivalent function may be
called monadically, and you can trap the condition of no left arg. But
you cannot readily trap the no-args situation.
Thus, if one wanted to define an identity element for one's own
function, and have it recognized by reduce, I don't think it could be
done as straightforwardly (if perhaps inelegantly) as in Perl. Seems a
bit ironic.
Anyway, I find your efforts inspiring. I have not tended to do much
vector-algebraic stuff in Perl, except what I can do directly with map
and maybe grep. Knowing APL is always there makes me lazy I guess.
It's really nice to see a useful flow of ideas from APL to Perl, and I
think many people would be pleased to see more in the opposite direction
as well.
BTW, I agree that the local-variable approach is probably more readable,
and the vagaries of dynamic scoping are all too familiar to APLers. But
I think your use of function references is particularly instructive.
There's little like it in APL that I can think of -- although APL
operators, taking functions as operands, are extremely powerful. There
is the char string analogue of symbolic refs, using the APL execute, but
it's really an eval so it's not the same thing as a real reference.
Definitely fun stuff.
Joe
------------------------------
Date: 17 Nov 1999 14:56:27 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Unload/reload modules?
Message-Id: <80ufmr$57c$1@pegasus.csx.cam.ac.uk>
Kragen Sitaker <kragen@dnaco.net> wrote:
>
>You can indeed reload the module; see perldoc perlvar on %INC.
>However, the import() method of a module can do arbitrarily evil
>things; there's no easy way to undo them because you don't know what
>they are.
But if it's your own module, you can ensure such nasty things don't
happen.
Mike Guy
------------------------------
Date: Wed, 17 Nov 1999 14:12:18 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Use sort function with reference to subroutine?
Message-Id: <3832B7DD.4321878B@home.com>
[posted & mailed]
Thelma Lubkin wrote:
>
> #!/usr/bin/perl -w
> use strict;
>
> sub asub; #### Declare subroutine with sorting instructions
> my $subref = \&asub; #### Reference to the subroutine
>
> my @aray = (9, 14, 6, 11); #### An array to be sorted
>
> @aray = sort &$subref @aray; #### Attempt to use sort function: fails
^
perldoc -f sort
=item sort SUBNAME LIST
...
SUBNAME may be a scalar variable name (unsubscripted), in which case
the value provides the name of (or a reference to) the actual
^^^^^^^^^^^^^^^^^
subroutine to use.
So don't dereference your coderef.
@aray = sort $subref @aray;
Requires 5.005_03 or higher.
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: Wed, 17 Nov 1999 14:21:28 GMT
From: andrew-johnson@home.com (Andrew Johnson)
Subject: Re: Use sort function with reference to subroutine?
Message-Id: <IRyY3.3249$Zu4.41376@news1.rdc1.mb.home.com>
In article <80ucei$jnl$1@uwm.edu>,
Thelma Lubkin <thelma@alpha2.csd.uwm.edu> wrote:
! I am trying to use the perl sort function with a reference to a subroutine
[snip]
! @aray = sort &$subref @aray; #### Attempt to use sort function: fails
from: perldoc -f sort
=item sort SUBNAME LIST
[snip stuff]
If SUBNAME is specified, it gives the name of a subroutine that
returns an integer less than, equal to, or greater than C<0>,
depending on how the elements of the array are to be ordered. (The
C<E<lt>=E<gt>> and C<cmp> operators are extremely useful in such
routines.) SUBNAME may be a scalar variable name (unsubscripted), in
which case the value provides the name of (or a reference to) the
actual subroutine to use.
so either just use the scalar holding the reference (don't dereference
it with the &) or just use the subname itself:
@aray = sort $subref @aray;
@aray = sort asub @aray;
regards
andrew
--
Andrew L. Johnson http://www.manning.com/Johnson/
Reality is that which, when you stop believing in
it, doesn't go away.
-- Philip K. Dick
------------------------------
Date: 17 Nov 1999 14:29:20 GMT
From: Thelma Lubkin <thelma@alpha2.csd.uwm.edu>
Subject: Re: Use sort function with reference to subroutine?
Message-Id: <80ue40$gle$1@uwm.edu>
Rick Delaney <rick.delaney@home.com> wrote:
: Thelma Lubkin wrote:
:> #!/usr/bin/perl -w
:> use strict;
:>
:> sub asub; #### Declare subroutine with sorting instructions
:> my $subref = \&asub; #### Reference to the subroutine
:>
:> my @aray = (9, 14, 6, 11); #### An array to be sorted
:>
:> @aray = sort &$subref @aray; #### Attempt to use sort function: fails
: ^
: perldoc -f sort
: =item sort SUBNAME LIST
: ...
: SUBNAME may be a scalar variable name (unsubscripted), in which case
: the value provides the name of (or a reference to) the actual
: ^^^^^^^^^^^^^^^^^
: subroutine to use.
: So don't dereference your coderef.
: @aray = sort $subref @aray;
: Requires 5.005_03 or higher.
..ah, there's my problem, then. I actually did try
that, and got this:
Not a GLOB reference at try1 line 9.
But perl -v shows,
This is perl, version 5.004_04 built for alpha-dec_osf
Copyright 1987-1997, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5.0 source kit.
so I guess I can't do it using the University's perl installation.
thank you.
--thelma
: --
: Rick Delaney
: rick.delaney@home.com
------------------------------
Date: Wed, 17 Nov 1999 16:35:55 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: Use sort function with reference to subroutine?
Message-Id: <LPAY3.1252$zl1.226109@news.itd.umich.edu>
In article <80ue40$gle$1@uwm.edu>,
Thelma Lubkin <thelma@alpha2.csd.uwm.edu> wrote:
>Rick Delaney <rick.delaney@home.com> wrote:
>: Thelma Lubkin wrote:
>:> @aray = sort &$subref @aray; #### Attempt to use sort function: fails
>: SUBNAME may be a scalar variable name (unsubscripted), in which case
>: the value provides the name of (or a reference to) the actual
>: ^^^^^^^^^^^^^^^^^
>: subroutine to use.
>: Requires 5.005_03 or higher.
> ..ah, there's my problem, then. I actually did try
> that, and got this:
> Not a GLOB reference at try1 line 9.
>so I guess I can't do it using the University's perl installation.
>thank you.
Sure you can.
@aray = sort { &$subref() } @aray;
--
Sean McAfee mcafee@umich.edu
print eval eval eval eval eval eval eval eval eval eval eval eval eval eval
q!q@q#q$q%q^q&q*q-q=q+q|q~q:q? Just Another Perl Hacker ?:~|+=-*&^%$#@!
------------------------------
Date: 17 Nov 1999 16:56:22 GMT
From: Thelma Lubkin <thelma@alpha2.csd.uwm.edu>
Subject: Re: Use sort function with reference to subroutine?
Message-Id: <80umnm$ht5$1@uwm.edu>
Sean McAfee <mcafee@waits.facilities.med.umich.edu> wrote:
: In article <80ue40$gle$1@uwm.edu>,
: Thelma Lubkin <thelma@alpha2.csd.uwm.edu> wrote:
:>Rick Delaney <rick.delaney@home.com> wrote:
:>: Thelma Lubkin wrote:
:>:> @aray = sort &$subref @aray; #### Attempt to use sort function: fails
:>: SUBNAME may be a scalar variable name (unsubscripted), in which case
:>: the value provides the name of (or a reference to) the actual
:>: ^^^^^^^^^^^^^^^^^
:>: subroutine to use.
:>: Requires 5.005_03 or higher.
:> ..ah, there's my problem, then. I actually did try
:> that, and got this:
:> Not a GLOB reference at try1 line 9.
:>so I guess I can't do it using the University's perl installation.
:>thank you.
: Sure you can.
: @aray = sort { &$subref() } @aray;
Thank you -- that does it.
This is a tremendously helpful group.
--thelma
: --
: Sean McAfee mcafee@umich.edu
: print eval eval eval eval eval eval eval eval eval eval eval eval eval eval
: q!q@q#q$q%q^q&q*q-q=q+q|q~q:q? Just Another Perl Hacker ?:~|+=-*&^%$#@!
------------------------------
Date: Wed, 17 Nov 1999 15:48:29 GMT
From: "Craig Vincent" <webmaster@webdream.com>
Subject: Using Apache::AuthenDBI
Message-Id: <h7AY3.705$Zj1.572@198.235.216.4>
I'm using Apache 1.3.9/mod_perl w/ Apache::DBI & Apache::AuthenDBI (Latest
versions)
Server: Linux RedHat 6.1
I'm using the following .htaccess for basic authentication over a MySQL
database
<snip>
AuthName DBI
AuthType Basic
#authenticate via DBI
PerlAuthenHandler Apache::AuthenDBI
PerlSetVar Auth_DBI_data_source dbi:mysql:members
PerlSetVar Auth_DBI_username foo
PerlSetVar Auth_DBI_password bar
#DBI->connect($data_source,$username,$password)
</snip>
The problem lies is that this does it's authentication based on the MySQL
server being on the same server (localhost).
What I want to do is actually do the authentication using a database on a
remote server...however the docs don't seem to
mention anything of the kind nor have I found any working solutions through
the Deja archives.
Has anyone attempted to do something similar and been successful? Or have
any theories on how this may be achieved?
--
Sincerely,
Craig Vincent
Senior Webmaster/Programmer
Web Dream Inc.
------------------------------
Date: Wed, 17 Nov 1999 11:06:34 -0500
From: Craig Ciquera <craig@mathworks.com>
Subject: Re: Using Apache::AuthenDBI
Message-Id: <3832D28A.2B9AE4E7@mathworks.com>
The full DSN is something like the following:
dbi:DRIVER:DB_NAME:DB_SERVER
I am assuming in your example below that members is the name of the Database.
Have you tried placing the name of the server in the DSN???
-Craig
Craig Vincent wrote:
> I'm using Apache 1.3.9/mod_perl w/ Apache::DBI & Apache::AuthenDBI (Latest
> versions)
> Server: Linux RedHat 6.1
>
> I'm using the following .htaccess for basic authentication over a MySQL
> database
>
> <snip>
> AuthName DBI
> AuthType Basic
>
> #authenticate via DBI
> PerlAuthenHandler Apache::AuthenDBI
>
> PerlSetVar Auth_DBI_data_source dbi:mysql:members
> PerlSetVar Auth_DBI_username foo
> PerlSetVar Auth_DBI_password bar
> #DBI->connect($data_source,$username,$password)
> </snip>
>
> The problem lies is that this does it's authentication based on the MySQL
> server being on the same server (localhost).
> What I want to do is actually do the authentication using a database on a
> remote server...however the docs don't seem to
> mention anything of the kind nor have I found any working solutions through
> the Deja archives.
>
> Has anyone attempted to do something similar and been successful? Or have
> any theories on how this may be achieved?
>
> --
> Sincerely,
>
> Craig Vincent
> Senior Webmaster/Programmer
> Web Dream Inc.
------------------------------
Date: Wed, 17 Nov 1999 09:17:07 -0600
From: Tom Briles <sariq@texas.net>
Subject: Re: Wierd List Behavior
Message-Id: <3832C6F3.72ADF894@texas.net>
tigger149@my-deja.com wrote:
>
> Ok I found some wierd behavior. I am wondering if this is a perl bug or
'weird', you mean. That particular misspelling really bugs me for some
reason. Perhaps because it's weird.
> if it is documented somewhere?
Yes.
> Here is some example code:
>
> ($a,$b,$) = ('First',,'Third');
I assume that you meant:
($a,$b,$c) = ('First',,'Third');
>
> print "A: $a B: $b C: $c";
>
> -------------------
>
> The output of the code would look like:
>
> A: First B: Third C:
This behavior is documented in perldata.
Good luck with it!
- Tom
------------------------------
Date: Wed, 17 Nov 1999 09:18:45 -0600
From: Tom Briles <sariq@texas.net>
Subject: Re: Wierd List Behavior
Message-Id: <3832C755.F5B47B9B@texas.net>
Kragen Sitaker wrote:
>
> In article <SDnY3.20047$YI2.867288@typ11.nn.bcandid.com>,
> Kragen Sitaker <kragen@dnaco.net> wrote:
> >In article <80ssnm$s3p$1@nnrp1.deja.com>, <tigger149@my-deja.com> wrote:
> >>Ok I found some wierd behavior. I am wondering if this is a perl bug or
> >>if it is documented somewhere?
> >
> >I think Perl should report a parse error for two commas in a row.
>
> This may not have been clear: I think it would be a good idea for Perl
> to treat this as a parse error.
Warning, perhaps. Error, no.
> I intended no opinion on what I
> expected Perl to do; I take your word for it that it does as you report.
It does, and, as I posted earlier, is documented.
- Tom
------------------------------
Date: Wed, 17 Nov 1999 15:39:18 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Wierd List Behavior
Message-Id: <G_zY3.21486$YI2.964425@typ11.nn.bcandid.com>
In article <3832C755.F5B47B9B@texas.net>, Tom Briles <sariq@texas.net> wrote:
>Kragen Sitaker wrote:
>> >I think Perl should report a parse error for two commas in a row.
>>
>> This may not have been clear: I think it would be a good idea for Perl
>> to treat this as a parse error.
>
>Warning, perhaps. Error, no.
Why not?
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Wed, 17 Nov 1999 10:21:20 -0600
From: Tom Briles <sariq@texas.net>
Subject: Re: Wierd List Behavior
Message-Id: <3832D600.492EE854@texas.net>
Kragen Sitaker wrote:
>
> In article <3832C755.F5B47B9B@texas.net>, Tom Briles <sariq@texas.net> wrote:
> >Kragen Sitaker wrote:
> >> >I think Perl should report a parse error for two commas in a row.
> >>
> >> This may not have been clear: I think it would be a good idea for Perl
> >> to treat this as a parse error.
> >
> >Warning, perhaps. Error, no.
>
> Why not?
This is Perl. IMHO, the question is 'Why?'.
If the answer is not compelling, then don't criminalize the behavior.
- Tom
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 1408
**************************************