[17453] in Perl-Users-Digest
Perl-Users Digest, Issue: 4873 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 12 14:05:34 2000
Date: Sun, 12 Nov 2000 11:05:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <974055910-v9-i4873@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 12 Nov 2000 Volume: 9 Number: 4873
Today's topics:
Re: "Programming the Perl DBI" <mikecook@cigarpool.com>
A surprise with vec() <rajasankark@my-deja.com>
Re: A surprise with vec() (Martien Verbruggen)
Re: A surprise with vec() (Gwyn Judd)
activeperl: reading registry <me@privacy.net>
Re: activeperl: reading registry <carvdawg@patriot.net>
Authentication w/Apache+Perl+MySQL (Jonaskuh)
Re: Authentication w/Apache+Perl+MySQL <David.Hiskiyahu@alcatel.be>
Re: CGI.pm + exec = error <David.Hiskiyahu@alcatel.be>
Help about sending over 1000 mails error!! <lukus@hongkong.com>
Re: Help about sending over 1000 mails error!! <adalessandro@odione.com>
Re: How to call a perl script from HTML <David.Hiskiyahu@alcatel.be>
Re: How to call sub routines from a CGI made Form <rosie@dozyrosy.plus.com>
Re: How to call sub routines from a CGI made Form <thectrain@hotmail.com>
HTML::Mason question: passing references (the old fashi <hlslaughter@hotmail.com>
Re: HTML::Mason question: passing references (the old f <iltzu@sci.invalid>
Re: Log.pm did not return a true value <iltzu@sci.invalid>
Re: Performance/scaleablility question: Perl/CGI vs. J (Randal L. Schwartz)
Re: perl5porters: defined @array depricated? -- PROBLEM (Randal L. Schwartz)
Re: Please Help - Student question regarding Flock and <Juha.Laiho@iki.fi>
Re: Pushing a hash on to a stack... (Christopher Burke)
Re: Pushing a hash on to a stack... (Gwyn Judd)
Re: Pushing a hash on to a stack... <ren.maddox@tivoli.com>
Re: Random Array with Sort? <joe+usenet@sunstarsys.com>
Re: Random Array with Sort? <iltzu@sci.invalid>
Re: Random Array with Sort? <joe+usenet@sunstarsys.com>
Re: Random Array with Sort? (Randal L. Schwartz)
Re: Random Array with Sort? <quantum_mechanic@my-deja.com>
Re: What is the point of the new keyword 'our'? <brannon@lnc.usc.edu>
will this locking get me in trouble? <webqueen@my-deja.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 12 Nov 2000 09:06:28 -0700
From: "Michael Cook" <mikecook@cigarpool.com>
Subject: Re: "Programming the Perl DBI"
Message-Id: <nezP5.751$sg3.116046@news.uswest.net>
$20.50 brand new from http://www.bookpool.com
Michael
--
== CigarPool ==
http://www.cigarpool.com
"David" <qx11@cornell.edu> wrote in message
news:8FE9EED1Fqx11cornelledu@132.236.56.8...
> "Programming the Perl DBI"
> by Alligator Descartes, Tim Bunce
> Paperback - 346 pages (February 2000)
> O'Reilly & Associates; ISBN: 1565926994
> Brand New Condition, Asking $25
------------------------------
Date: Sun, 12 Nov 2000 11:50:08 GMT
From: Rajasankar <rajasankark@my-deja.com>
Subject: A surprise with vec()
Message-Id: <8um05f$mhf$1@nnrp1.deja.com>
Hi,
I would like to understand this behavior of vec.
When I run the following,
# Starting of the script
$x = 0;
vec ($x, 3, 1) = 1;
print "x is $x\n";
#end of the script
the result is
x is 8
That is fine.
But when I run this,
# Starting of the script
$x = 0;
vec ($x, 4, 1) = 1;
print "x is $x\n";
#end of the script
the result is,
x is 0
Wheras I expect 16.
Can somebody please enlighten me.
This happens in my solaris 2.6 system with perl5.6.
Thanks,
Raja.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sun, 12 Nov 2000 23:38:31 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: A surprise with vec()
Message-Id: <slrn90t3q7.gs3.mgjv@martien.heliotrope.home>
On Sun, 12 Nov 2000 11:50:08 GMT,
Rajasankar <rajasankark@my-deja.com> wrote:
>
>
> Hi,
>
> I would like to understand this behavior of vec.
>
> When I run the following,
>
> # Starting of the script
> $x = 0;
> vec ($x, 3, 1) = 1;
> print "x is $x\n";
> #end of the script
You're missing a few packs and unpacks. Check out the example at the end
of the description of vec() in perlfunc.
$x = pack "B*", "0" x 8;
vec($x, 3, 1) = 1;
$x = unpack "C", $x;
print $x;
> This happens in my solaris 2.6 system with perl5.6.
In that case:
$ man perlfunc
look for pack, unpack and vec.
Martien
--
Martien Verbruggen |
Interactive Media Division | Freudian slip: when you say one thing
Commercial Dynamics Pty. Ltd. | but mean your mother.
NSW, Australia |
------------------------------
Date: Sun, 12 Nov 2000 12:40:01 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: A surprise with vec()
Message-Id: <slrn90t3sv.pt9.tjla@thislove.dyndns.org>
I was shocked! How could Rajasankar <rajasankark@my-deja.com>
say such a terrible thing:
>Wheras I expect 16.
>Can somebody please enlighten me.
>
>This happens in my solaris 2.6 system with perl5.6.
I get that too (linuxppc with 5.6). Looks like a bug to me.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Abstainer: A weak person who yields to the temptation of denying himself
a pleasure.
------------------------------
Date: Sun, 12 Nov 2000 16:49:25 GMT
From: "EM" <me@privacy.net>
Subject: activeperl: reading registry
Message-Id: <pSzP5.3071$Nw6.9502@news.iol.ie>
i have windows me with activeperl installed
is there a way to read/write a key from the windows registry?
thanks in advance
------------------------------
Date: Sun, 12 Nov 2000 12:42:44 -0500
From: H C <carvdawg@patriot.net>
Subject: Re: activeperl: reading registry
Message-Id: <3A0ED694.1A121115@patriot.net>
Check the docs for Win32::TieRegistry
EM wrote:
> i have windows me with activeperl installed
> is there a way to read/write a key from the windows registry?
>
> thanks in advance
--
Q: Why is Batman better than Bill Gates?
A: Batman was able to beat the Penguin.
------------------------------
Date: Sun, 12 Nov 2000 15:09:15 GMT
From: jonaskuh@tell-em-off.com (Jonaskuh)
Subject: Authentication w/Apache+Perl+MySQL
Message-Id: <3a0eb1da.35337450@news.coastalnet.com>
Would someone throw me a bone please? I'm trying to get Perl to
Authenticate and authorize users site wide. I need to have the script
pull the user/pass from a MySQL database, and then integrate it with
Apache to make some sort of ticketing system. Can anyone help me get
started? I've been working this one for a while..
Thanks,
Jason
------------------------------
Date: Sun, 12 Nov 2000 19:24:07 +0100
From: David Hiskiyahu <David.Hiskiyahu@alcatel.be>
To: Jonaskuh <jonaskuh@tell-em-off.com>
Subject: Re: Authentication w/Apache+Perl+MySQL
Message-Id: <3A0EE047.9C951E8C@alcatel.be>
I may have invented the wheel, but the simplest and well working solution
was as follows (used a flat file but could have used MySQL as well):
Make a bunch of pages to let users introduce userid/passwords for themselves,
could limit granting access to an administrator user.
Store user info in a flatfile, similar to 'etc/passwd', with password
encrypted - use Perl function 'crypt' for that password.
From your ticketing system ask users to provide a userid/password, encrypt
the given password and match with the user password in your security file.
This will be as good as any UNIX password system, almost, you will just need
to check user info for bad passwords.
----------------------
Another way, may work sometimes - assuming all your users have a working
account on some system, e.g. on your corporate Intranet.
Ask for the existing userid/passwd on that Intranet server, and from your
Perl program attempt a fake FTP session with the userid/passwd.
If no error messages detected during the FTP session, assume user authenticated.
----------------------
Well, all above will let a user prove that he is who he claims, to authenticate him.
You would then probably need to do some authorization as well - meaning that you
will need means to check who may do what.
I had all that hand done on 1-day work - I wonder how much time it would take to
search for such info.
David.
Jonaskuh wrote:
>
> Would someone throw me a bone please? I'm trying to get Perl to
> Authenticate and authorize users site wide. I need to have the script
> pull the user/pass from a MySQL database, and then integrate it with
> Apache to make some sort of ticketing system. Can anyone help me get
> started? I've been working this one for a while..
>
> Thanks,
> Jason
--
*** David Hiskiyahu, Alcatel SRD, 1 Fr.Wellesplein, Antwerp ***
*** Phone/Fax: +32 3 240 7965/9820, private +32 3 290 0912 ***
Quote of the day:
You can fool too many of the people too much of the time.
- James Thurber
------------------------------
Date: Sun, 12 Nov 2000 18:56:40 +0100
From: David Hiskiyahu <David.Hiskiyahu@alcatel.be>
To: andre_sanchez@my-deja.com
Subject: Re: CGI.pm + exec = error
Message-Id: <3A0ED9D8.27F83233@alcatel.be>
Andre,
The CGI module is quite convenient, but this is how we lose a bit
our touch with how this stuff works inside.
Who the hell can guess why "new CGI('')" is better "than new CGI;"?
I remember that not so long ago I was writing CGI stuff in a 'raw'
mode, going directly to the ENV hash or to the STDIN, and seeing
what is inside the POST and GET method.
It was never then a problem to exec conveniently from one script
to another once the first script has figured out that the task is
exactly for the other one!
I admit again the convenience of the CGI module, but haven't we
lost something with it?
David.
andre_sanchez@my-deja.com wrote:
>
> > If my ideas are greatly appreciated why have you not tried
> > implementing them?
>
> Quite the contrary; I am more than grateful for your help and have
> carefully studied your advice. But, I am also stubborn and ignorant of
> many things relating to Perl.
>
> > Look at he description of the new() method in the manuals for
> > CGI.pm. This will explain how you can create a CGI object in ways
> > other than using the CGI interface.
>
> I found this instructive since changing this:
>
> my $query = new CGI;
>
> to this:
>
> my $query = new CGI('');
>
> got me what I wanted. Thank you.
>
> Andre Sanchez
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
--
*** David Hiskiyahu, Alcatel SRD, 1 Fr.Wellesplein, Antwerp ***
*** Phone/Fax: +32 3 240 7965/9820, private +32 3 290 0912 ***
Quote of the day:
You can fool too many of the people too much of the time.
- James Thurber
------------------------------
Date: Mon, 13 Nov 2000 01:06:08 +0800
From: "Regent Linus" <lukus@hongkong.com>
Subject: Help about sending over 1000 mails error!!
Message-Id: <8umijt$j3k4@imsp212.netvigator.com>
Hi
My work is maintaining a site, and I am trying to
send HTML based mails to my mailing list by MIME::Lite
module when my site have some updates.
However, My codes seem run not very good, it returns
some error messages when sending over 300 or sometimes
200 mails out:
>>>>>>>>>>>>>>>>>>>>>>>>>>
Can't open /dev/null: Too many open files in system
and sometimes
>>>>>>>>>>>>>>>>>>>>>>>>>>>
/usr/lib/sendmail: error in loading shared libraries: libdb.so.3: cannot
open sh
ared object file: Error 23
open |/usr/lib/sendmail -t -oi -oem: Too many open files in system
==============================================
use MIME::Lite;
my $FILE_SRC='mail_list.txt';
my $send_from=' "Webmaster" <webmaster@my.com>';
open(HTMLSRC, "<update.htm");
undef $/; $HTML=<HTMLSRC>; $/="\n";
close(HTMLSRC);
$cnt = 0;
open(MAILS, "<$FILE_SRC");
while (<MAILS>){
chomp;
$cnt++;
&send_mail("$_");
if (not $cnt%100) {
$thou = $cnt/100;
print $thou."00 mails over\n";
}
}
close(MAILS);
print "Total $cnt emails sent.\n";
sub send_mail{
$recipient = $_[0];
$msg = MIME::Lite->new(
From =>"$send_from",
To =>"$recipient",
Subject =>'Update news',
Type =>'multipart/related'
);
$msg->attach(
Type => 'text/html',
Data => qq{ $HTML }
);
$msg->send;
}
======================================
Could somebody tell me where I am going wrong?
thanks very very much.
------------------------------
Date: Sun, 12 Nov 2000 13:14:02 -0500
From: "Arthur Dalessandro" <adalessandro@odione.com>
Subject: Re: Help about sending over 1000 mails error!!
Message-Id: <t0tnfbh8r27hdf@corp.supernews.com>
Sounds like an O/S problem, more specifically a unix problem.
"Regent Linus" <lukus@hongkong.com> wrote in message
news:8umijt$j3k4@imsp212.netvigator.com...
> Hi
>
> My work is maintaining a site, and I am trying to
> send HTML based mails to my mailing list by MIME::Lite
> module when my site have some updates.
>
> However, My codes seem run not very good, it returns
> some error messages when sending over 300 or sometimes
> 200 mails out:
>
> >>>>>>>>>>>>>>>>>>>>>>>>>>
> Can't open /dev/null: Too many open files in system
>
> and sometimes
> >>>>>>>>>>>>>>>>>>>>>>>>>>>
> /usr/lib/sendmail: error in loading shared libraries: libdb.so.3: cannot
> open sh
> ared object file: Error 23
> open |/usr/lib/sendmail -t -oi -oem: Too many open files in system
>
>
> ==============================================
> use MIME::Lite;
>
> my $FILE_SRC='mail_list.txt';
> my $send_from=' "Webmaster" <webmaster@my.com>';
>
> open(HTMLSRC, "<update.htm");
> undef $/; $HTML=<HTMLSRC>; $/="\n";
> close(HTMLSRC);
>
> $cnt = 0;
> open(MAILS, "<$FILE_SRC");
>
> while (<MAILS>){
> chomp;
> $cnt++;
> &send_mail("$_");
>
> if (not $cnt%100) {
> $thou = $cnt/100;
> print $thou."00 mails over\n";
> }
> }
>
> close(MAILS);
>
> print "Total $cnt emails sent.\n";
>
> sub send_mail{
> $recipient = $_[0];
> $msg = MIME::Lite->new(
> From =>"$send_from",
> To =>"$recipient",
> Subject =>'Update news',
> Type =>'multipart/related'
> );
>
> $msg->attach(
> Type => 'text/html',
> Data => qq{ $HTML }
> );
>
> $msg->send;
> }
>
> ======================================
>
>
>
> Could somebody tell me where I am going wrong?
> thanks very very much.
>
>
>
>
------------------------------
Date: Sun, 12 Nov 2000 19:12:49 +0100
From: David Hiskiyahu <David.Hiskiyahu@alcatel.be>
To: Bill <Bill@net.com>
Subject: Re: How to call a perl script from HTML
Message-Id: <3A0EDDA1.F4E8A876@alcatel.be>
Bill,
If my guess is right, you want to kick a perl script by downloading
a simple html page, without clicking something later on that page.
The only way I found for that when I needed to do a similar things was
via a fake IMG tag:
<IMG SRC=http://somewhere.com/myscript.cgi?params_if_any>
The script could even really print out am image, to avoid a broken
image icon on the screen.
A very typical example is a Counter.cgi script - it is called by an
HTML page, runs a script, provides a graphical output.
As such, I believe that HTML should have foreseen an explicit way
of asking from a downloaded page to run a program and to include
the output in the viewed page.
David.
Bill wrote:
>
> > You mean like:
> > <a
> >
> href="/cgi-bin/myfile.pl?firstvalue=something&secondvalue=something">Execute
> > the script!</a>
> > Is that what you wanted?
>
> Yes, that's it exactly.
>
> href="/cgi-bin/myfile.pl"
>
> When I do that it simply dispalys the perl program.
>
> Thanks
>
> -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> -----== Over 80,000 Newsgroups - 16 Different Servers! =-----
--
*** David Hiskiyahu, Alcatel SRD, 1 Fr.Wellesplein, Antwerp ***
*** Phone/Fax: +32 3 240 7965/9820, private +32 3 290 0912 ***
Quote of the day:
You can fool too many of the people too much of the time.
- James Thurber
------------------------------
Date: Sun, 12 Nov 2000 11:50:39 -0000
From: Rosemary I H Powell <rosie@dozyrosy.plus.com>
Subject: Re: How to call sub routines from a CGI made Form
Message-Id: <MPG.147803ecf55bae30989728@usenet.plus.net>
In article <syjP5.6369$24.476677@news0.telusplanet.net> dated Sat, 11 Nov
2000 22:15:52 GMT, our revered colleague Matt Perzel
(thectrain@hotmail.com) was so kind as to advise ...
> I know this is more a cgi question but I am using perl so I guess it applies
> here. Anyway I am making a form parsing script, in perl, that displays the
> data and then has a button that when you click it sends it to a text file. I
> can do all of the above except get the button to write the data. Is there a
> way to call the routine from a form action?
>
> This is what I am thinking but it doesn't seem to work
>
> print "<FORM name=\"FORM1\" action=&writeData>";
>
> Thanks
You need to make the form action call your script NOT your routine, but
also send (and check in your script for) a value that tells the script
to call that routine.
Then check your input parameters in the script for this value, and if it
is set, call your &writeData routine...
HTH, Rosemary
--
----------------------------------------------------------------
| Rosemary I.H.Powell EMail: Home: rosie@dozyrosy.plus.com |
| Work: r.i.h.powell@rl.ac.uk |
| http://NeedleworkSamplers.com/ |
| http://www.CavalierKingCharles.com/ |
----------------------------------------------------------------
------------------------------
Date: Sun, 12 Nov 2000 18:48:22 GMT
From: "Matt Perzel" <thectrain@hotmail.com>
Subject: Re: How to call sub routines from a CGI made Form
Message-Id: <WBBP5.13731$sz3.1922995@news1.telusplanet.net>
Thanks for your reply I got it working and it works perfect.
"Rosemary I H Powell" <rosie@dozyrosy.plus.com> wrote in message
news:MPG.147803ecf55bae30989728@usenet.plus.net...
> In article <syjP5.6369$24.476677@news0.telusplanet.net> dated Sat, 11 Nov
> 2000 22:15:52 GMT, our revered colleague Matt Perzel
> (thectrain@hotmail.com) was so kind as to advise ...
>
> > I know this is more a cgi question but I am using perl so I guess it
applies
> > here. Anyway I am making a form parsing script, in perl, that displays
the
> > data and then has a button that when you click it sends it to a text
file. I
> > can do all of the above except get the button to write the data. Is
there a
> > way to call the routine from a form action?
> >
> > This is what I am thinking but it doesn't seem to work
> >
> > print "<FORM name=\"FORM1\" action=&writeData>";
> >
> > Thanks
>
> You need to make the form action call your script NOT your routine, but
> also send (and check in your script for) a value that tells the script
> to call that routine.
>
> Then check your input parameters in the script for this value, and if it
> is set, call your &writeData routine...
>
> HTH, Rosemary
>
> --
> ----------------------------------------------------------------
> | Rosemary I.H.Powell EMail: Home: rosie@dozyrosy.plus.com |
> | Work: r.i.h.powell@rl.ac.uk |
> | http://NeedleworkSamplers.com/ |
> | http://www.CavalierKingCharles.com/ |
> ----------------------------------------------------------------
------------------------------
Date: Sun, 12 Nov 2000 04:08:07 -0800
From: "Harry Slaughter" <hlslaughter@hotmail.com>
Subject: HTML::Mason question: passing references (the old fashioned way)
Message-Id: <HKvP5.323$el3.239971@news.pacbell.net>
I'd like to be able to set values in mason's %ARGS hash from a perl
component.
in a normal script, i might do this:
somefunc(\%hash);
sub somefunc {
my($hashref)=@_;
$$hashref{somekey}=1;
return();
}
but this does not work with mason logic such as:
## top component
% my $foo = $m->comp("comp/changeargs", \%ARGS);
foo is <% $ARGS{foo} %><P>
## comp/changeargs
<%perl>
$ref=@_;
$ref{foo}="foo";
return();
</%perl>
at this point it looks like i'm going to have to do in the sub-component
what i want to do in the parent component and return a blob of html rather
than just create/modify %ARGS values, as i'd like to. but i'd really like
to have sub-components that don't even anything to do with writing html.
and yes, i'm new to mason : )
tks
h
------------------------------
Date: 12 Nov 2000 17:47:06 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: HTML::Mason question: passing references (the old fashioned way)
Message-Id: <974049895.20521@itz.pp.sci.fi>
[Crossposted and followups set to clp.modules. The Mason mailing list
might be an even better place for this discussion.]
In article <HKvP5.323$el3.239971@news.pacbell.net>, Harry Slaughter wrote:
>
>## top component
>% my $foo = $m->comp("comp/changeargs", \%ARGS);
>foo is <% $ARGS{foo} %><P>
[Serious snippage since I had trouble isolating the relevant bits..]
% $m->comp("comp/changeargs", foobar => \%ARGS);
Then, in the subcomponent, declare "foobar" as a scalar argument and
modify the hash %$foobar as you like.
But why do it so hard? You could just write "foo is <% $foo %><P>"
and pass the value in the return() statement in the subcomponent.
You could even return whole hashes that way. While the parameter
passing system for Mason components is different, they really are
ordinary Perl subroutines underneath all the Mason stuff and return
values will work as expected.
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post
something, we discuss its implications. If the discussion happens to
answer a question you've asked, that's incidental." -- nobull in clpm
------------------------------
Date: 12 Nov 2000 17:13:17 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Log.pm did not return a true value
Message-Id: <974048988.19276@itz.pp.sci.fi>
In article <8u8i38$uti$1@lublin.zrz.tu-berlin.de>, Anno Siegel wrote:
>Jeff Zucker <jeff@vpservices.com> wrote in comp.lang.perl.misc:
>>dick dijk wrote:
>
>>> How can I make it work?
>>
>>By following the instructions as listed in perldiag: put "1;" at the end
>>of the file to be included (without the quotes).
>
>As it happens, it even works with the quotes.
I usually end my modules with "That's all, folks!", though I've
occasionally used other appropriate quotes.
"false" would be just plain silly.
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post
something, we discuss its implications. If the discussion happens to
answer a question you've asked, that's incidental." -- nobull in clpm
------------------------------
Date: 12 Nov 2000 04:11:24 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Performance/scaleablility question: Perl/CGI vs. Java Servlets?
Message-Id: <m1g0kxs843.fsf@halfdome.holdit.com>
>>>>> "David" == David Sisk <davesisk@ipass.net> writes:
David> So, has anyone had experience with both of these technologies
David> and been able to compare them from a performance and
David> scaleability perspective? I'm looking for some objective
David> answers, or some links with objective results to help answer
David> this question for me...
Both "perl.org" and "perl.com" have separate (and occasionally
overlapping) "Perl Success Stories". Use the relevant links on each
site.
Summary: Perl is used for LARGE REAL-WORLD MISSION-CRITICAL apps.
It's not a toy. It's the real thing.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 12 Nov 2000 04:24:19 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: perl5porters: defined @array depricated? -- PROBLEMS!
Message-Id: <m18zqps7ik.fsf@halfdome.holdit.com>
>>>>> "Jari" == Jari Aalto+mail perl <jari.aalto@poboxes.com> writes:
Jari> Module A. Declares an array
Package variables are not declared. They are instantiated, usually at
runtime, by merely assigning them a value. defined() doesn't make
sense here.
Lexical variables are not visible outside of the scope of the file
(or block) in which they are declared.
Jari> Module B. Wants to see if that array exists - maybe the name has
Jari> been renamed in later versions of the module...
Jari> --> defined works but is depricated.
Jari> `if' is recommended but doesn't work ???
In neither case should B be poking around in A's namespace to figure
out what is there. Too much introspection can lead to coupling-hell.
Do not use defined() on aggregates (hash/array). It does not report
what you'd want it to report, and this is not considered a bug except
in the mind of the users who want it to mean something like
"declared". It doesn't mean that. It means "memory has been
allocated", which for efficiency is handled in a lazy way.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 12 Nov 2000 11:06:48 +0200
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: Please Help - Student question regarding Flock and Semop Modules?
Message-Id: <8ulmj8$6bt$1@ichaos.ichaos-int>
"Dave Turing" <DaveTuring@spam.co.uk> said:
>Which is considered the more advanced system and why? (flock or semop)
I think they're both good - but for different purposes.
>I do not fully understand semops, but it appears that an iterative loop
>"until state is achieved" is used by the semops method, as opposed to a
>suspension of the process by the operating system using constant ( 2)
>with flock.
>
>"Flock" appears the more efficient system as process control is handed to
>the operating system, whereby unnecessary programme cycles are suspended.
Hmm.. if Perl semop's are implemented at the OS level (using the SysV sem*()
calls), they suspend just as efficiently as flock().
What I see as the difference between the two is that semops feel more
"natural" to use with any kind of process synchronization, not just
locking access to a file, whereas flock is specific to the file being
locked. Of course, it's possible to implement generic semaphores
using vast number of lockable files, but that doesn't make sense. Also,
controlling file accesses by a semaphore sounds odd, as flock can be
readily used there, without the need to build any extra mechanisms.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a- C++ UH++++$ UL++++ P+@ L+++ E(-) W+$@ N++ !K w !O
!M V PS(+) PE Y+ PGP(+) t- 5? !X R tv--- b+ DI? D G e+ h--- r+++ y+
"...cancel my subscription to the resurrection!" (Jim Morrison)
------------------------------
Date: Sun, 12 Nov 2000 12:36:38 GMT
From: craznar@hotmail.com (Christopher Burke)
Subject: Re: Pushing a hash on to a stack...
Message-Id: <8FEAE5102Craznar@24.192.1.17>
mgjv@tradingpost.com.au (Martien Verbruggen) wrote in
<slrn90sihq.gs3.mgjv@martien.heliotrope.home>:
>and the answer was, yes, you can do it, using references. if you want to
>hide the fact that there are references, you use a function with a
>prototype that forces the reference, so that your code doesn't show
>explicit references. Or you do something like you suggested, although I
>would not use the word push anymore, and I would in the future avoid
>saying that there are no references. There are. they just are not
>explicitly mentioned, because that isn't necessary in Perl.
>
>Can we no assume that the question has been answered?
>
My decades of programming have obviously left the wrong meaning of
reference imprinted ... so I have no idea what the perl world actually
means by a reference. I'll just plod along with what I have.
I think we can assume that as someone not quite experienced enough with
PERL that I will not get my question answered.
I can live with that .....
--
---
/* Christopher Burke - Spam Mail to craznar@hotmail.com
|* www.craznar.com - International Internet Writing Experiment
\* Real mail to cburke(at)craznar(dot)com
------------------------------
Date: Sun, 12 Nov 2000 14:12:30 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Pushing a hash on to a stack...
Message-Id: <slrn90t9ac.qlu.tjla@thislove.dyndns.org>
I was shocked! How could Christopher Burke <craznar@hotmail.com>
say such a terrible thing:
>I think we can assume that as someone not quite experienced enough with
>PERL that I will not get my question answered.
Actually I think we can safely assume that your "I'm right and everyone
else is wrong, don't ask me for more information, oh and by the way I
already solved the problem, and don't tell me anything I might not have
already known because I'm such a genius, don't try to suggest a
different way to do it because then you *must* be attacking me" attitude
has landed you in killfiles everywhere. But hey, you're in such good
company you'd probably think that's a good thing.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
The secret of healthy hitchhiking is to eat junk food.
------------------------------
Date: 12 Nov 2000 11:19:37 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Pushing a hash on to a stack...
Message-Id: <m3g0kxjefq.fsf@dhcp11-177.support.tivoli.com>
craznar@hotmail.com (Christopher Burke) writes:
> mgjv@tradingpost.com.au (Martien Verbruggen) wrote in
> <slrn90sihq.gs3.mgjv@martien.heliotrope.home>:
>
> >Can we no assume that the question has been answered?
> >
>
> My decades of programming have obviously left the wrong meaning of
> reference imprinted ... so I have no idea what the perl world actually
> means by a reference. I'll just plod along with what I have.
Perhaps you could clarify exactly what meaning of reference your
decades of programming have left you with?
The meaning that we are using is that a reference is a handle, of
sorts, to another structure in memory. If you assign the reference to
another variable, you then have *two* references to the same structure
in memory. Changing either one is visible via both . For example,
you previously posted code similar to:
$hash{x} = 5;
$hash{y} = 10;
# some sort of push of the hash onto @array here
$array[0]{x} == 5 or die; # yes, I added the or die part
$array[0]{y} == 10 or die;
Here's the kicker, no matter *how* you accomplish the push there, be
it with an explicit reference (push @array, \%hash), an anonymous
reference (push @array, { %hash }), or some other method, the fact
that you are using this syntax to get to the values ($array[0]{x})
means that you can also do:
$hash_ref = $array[0];
$hash_ref->{x} = 15;
$array[0]{x} == 15 or die;
The point here is that $array[0] contains a *reference* to a hash. If
you assign that reference to another variable, then you now have two
references to the same hash. Modifying either one of them is the same
thing.
So, how does this differ from your meaning of reference?
> I think we can assume that as someone not quite experienced enough with
> PERL that I will not get my question answered.
Well, I suppose that depends on your question:
If your question is/was, "Can I enable the syntax $array[0]{x} to work
without using references?", then the answer is, "No, you cannot, that
uses references."
If your question is/was, "Can I use push to populate an array such
that the syntax $array[0]{x} works, without taking a reference to an
existing structure (i.e. \%hash)?", then the answer is "Yes, you just
need to use anonymous structures (i.e. { %hash })."
If your question is/was neither of these, then you'll probably need to
restate it to get an answer.
It is most certainly not true that people here don't want to answer
your question. I am certainly trying to do so and I know that others
are as well.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 12 Nov 2000 10:46:30 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Random Array with Sort?
Message-Id: <m3n1f5tcq1.fsf@mumonkan.sunstarsys.com>
James Taylor <james@NOSPAM.demon.co.uk> writes:
> Surely the point is that the outcome of any shuffling
> algorithm is dependent on the seed alone and if this
> is a 32 bit number then it can't be possible to generate
> more than 2**32 different permutations. So, if the array
> to be shuffled has more than 12 elements then you cannot
> hope to be able to generate all permutations, let alone
> generate those that you can with equal probability.
I agree. Hence running 100K consecutive F-Y trials on a
4 element list only measures the quality of your rand
implementation (i.e. the 4-point correlations of your
"rand" sequence).
However, by reseeding after you've gathered enough entropy
and incorporating this into your F-Y implementation, you
can get decent results out of a stock rand. The my_shuffle
implementation I posted hints at one way to do this,
but it's certainly not adequate as it stands.
Can you think of a better one?
--
Joe Schaefer
------------------------------
Date: 12 Nov 2000 16:32:13 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Random Array with Sort?
Message-Id: <974045858.14548@itz.pp.sci.fi>
In article <m3r94i157n.fsf@mumonkan.sunstarsys.com>, Joe Schaefer wrote:
>The Fisher-Yates algorithm is based on this fact. Here's
>an F-Y shuffle
>==============================
>#!/usr/bin/perl -w
>sub shuffle (@) {
> my $i = @_;
> while ($i > 0) {
> my $j = int rand($i+1); # HOW RANDOM ???
> next if $i-- == $j; # UGLY ;-)
> @_[$i,$j] = @_[$j,$i];
> }
>}
I think your implementation has a bug. The way you've written it, the
probability of selecting element $i (i.e. no swap occurring) is twice
as high as that of selecting any lower element. Here's a fix:
sub shuffle {
my $i = @_;
while ($i > 0) {
my $j = int rand($i--); # HOW RANDOM ???
@_[$i,$j] = @_[$j,$i];
}
}
That also got rid of the line marked "UGLY". I'm not quite sure, but
I would assume that restoring it would only hurt performance, since
the check is likely to take longer than the extra swap. I seem to
recall somebody having benchmarked this.
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post
something, we discuss its implications. If the discussion happens to
answer a question you've asked, that's incidental." -- nobull in clpm
------------------------------
Date: 12 Nov 2000 11:46:10 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Random Array with Sort?
Message-Id: <m3itptt9yl.fsf@mumonkan.sunstarsys.com>
Ilmari Karonen <iltzu@sci.invalid> writes:
> I think your implementation has a bug. The way you've written it, the
> probability of selecting element $i (i.e. no swap occurring) is twice
> as high as that of selecting any lower element. Here's a fix:
>
> sub shuffle {
> my $i = @_;
> while ($i > 0) {
> my $j = int rand($i--); # HOW RANDOM ???
> @_[$i,$j] = @_[$j,$i];
> }
> }
>
> That also got rid of the line marked "UGLY".
I think you're right- I like yours better anyway :)
> I would assume that restoring it would only hurt performance, since
> the check is likely to take longer than the extra swap. I seem to
> recall somebody having benchmarked this.
There was some discussion of benchmarks for F-Y about 1y ago;
here'a a URL:
http://faqchest.dynhost.com/prgm/perlu-l/perl-99/perl-9911/perl-991100/perl99110303_18504.html
--
Joe Schaefer
------------------------------
Date: 12 Nov 2000 10:04:38 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Random Array with Sort?
Message-Id: <m1snox6p8p.fsf@halfdome.holdit.com>
>>>>> "Joe" == Joe Schaefer <joe+usenet@sunstarsys.com> writes:
Joe> However, by reseeding after you've gathered enough entropy
Joe> and incorporating this into your F-Y implementation, you
Joe> can get decent results out of a stock rand. The my_shuffle
Joe> implementation I posted hints at one way to do this,
Joe> but it's certainly not adequate as it stands.
You're not reseeding though! (At least not in the "my_shuffle"
I saw you post.) You aren't pulling in any external info, so that
means there are still only 32K possible combinations of outputs!
Joe> Can you think of a better one?
The FAQ can. :)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Sun, 12 Nov 2000 18:38:17 GMT
From: Quantum Mechanic <quantum_mechanic@my-deja.com>
Subject: Re: Random Array with Sort?
Message-Id: <8umo2p$76j$1@nnrp1.deja.com>
In article <slrn90s1i4.kh5.tjla@thislove.dyndns.org>,
tjla@guvfybir.qlaqaf.bet (Gwyn Judd) wrote:
> I was shocked! How could Quantum Mechanic
<quantum_mechanic@my-deja.com>
> say such a terrible thing:
>
> >When I use your sort on ('a'..'c'), I get this distribution from 100K
> >trials:
>
> >Still very biased.
>
> Yeah. I think the 'sort' method is just wrong. Did you try the F/Y
> method on 'a'..'c'? When I did the results seemed very non-biased.
>
Yes, looking at F/Y prompted this thread. The distribution is always
as smooth as advertised. In fact, all permutations are generated very
quickly. (If someone were not sure how to generate permutations
directly, this would not be much slower. I haven't done the stats, but
it looks like the number of trials to generate all permutations averages
out to half a dozen trials per permutation).
The whole point of my initial post was to wonder out loud. Maybe we'll
all learn something new.
-QM
--
Quantum Mechanics: The dreams stuff is made of.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sun, 12 Nov 2000 13:25:17 GMT
From: Terrence Brannon <brannon@lnc.usc.edu>
Subject: Re: What is the point of the new keyword 'our'?
Message-Id: <lby9ypjpaa.fsf@lnc.usc.edu>
excellent answer.
> In article <39f840ad@news.barak.net.il>,
> Shimon Bollinger <bollinge@wholefamily.com> wrote:
> >I couldn't find an answer in the Perl 5.6 FAQ.
>
> It's to replace the old 'use vars' construction.
> (See http://www.plover.com/~mjd/perl/FAQs/Namespaces.html)
>
> The advantage over 'use vars' is that it has lexical scope, so you can
> declare that you'll be using a certainl global variable, but only
> inside of one block, and the global variable will still raise an error
> if you use it accidentally somewhere else.
>
--
Terrence Brannon
------------------------------
Date: Sun, 12 Nov 2000 17:38:46 GMT
From: webqueen, queen of the web <webqueen@my-deja.com>
Subject: will this locking get me in trouble?
Message-Id: <8umkj6$4ge$1@nnrp1.deja.com>
I'm updating a file from a remote system using File::Remote. Its am
htaccess password file, so Apache is using it to validate logins on the
local node. Also, perscripts open it (with my $r=flock(P, LOCK_SH) and
read from it node. No updates to the file occur on the local node, only
reads from Perl or Apache.
Is this safe? I don't think that file locking is possible with
File::Remote from what I can tell. Or will I discover a corrupt file one
of these days when Perl and/or Apache are reading when a remote update
comes in?
HUG,
PG
--
Time is nature's way of preventing everything from happening at once.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
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 4873
**************************************