[13077] in Perl-Users-Digest
Perl-Users Digest, Issue: 487 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 12 16:07:22 1999
Date: Thu, 12 Aug 1999 13:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 12 Aug 1999 Volume: 9 Number: 487
Today's topics:
02:Re: Problem reading forms with perl (UUCP)
code references to builtin functions (Darwin O.V. Alonso)
get data from flat file <mikej@1185design.com>
Re: List Files in a directory and search <makkulka@cisco.REMOVETHIS.com>
Re: List Files in a directory and search <rootbeer@redcat.com>
LWP <newsgroups@justinfashanu.demon.co.uk>
Re: Parse::RecDescent, optional subrules, and errors (Damian Conway)
Re: Perl Novice needs advice <Jeff.T.Parker@compaq.com>
Perl vs. ASP: which is better? (Kent Delcastillo)
Re: Perl vs. ASP: which is better? <jerrad@networkengines.com>
PTk loadc@my-deja.com
Re: s/// and interpolation <chris_conway@my-deja.com>
Re: Sesssion ID <uri@sysarch.com>
Re: Sesssion ID (Greg Bacon)
Re: Sesssion ID <tchrist@mox.perl.com>
Re: Sesssion ID <uri@sysarch.com>
Re: Sesssion ID (Kent Delcastillo)
Re: Sesssion ID <tchrist@mox.perl.com>
Re: Starnge DBI behavior <raison@mc.net>
Re: Why use Perl when we've got Python?! <arcege@shore.net>
Re: Win32 Perl won't display HTML <cassell@mail.cor.epa.gov>
Yet Another Newbie Question - Or Did I Find a Bug? churchylfem@my-deja.com
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 12 Aug 99 03:25:06 GMT
From: UUCP@p1.f3.n500.z2.hccfido.hcc.nl (UUCP)
Subject: 02:Re: Problem reading forms with perl
Message-Id: <13f_9908122146@hccfido.hcc.nl>
From: abigail@delanet.com (Abigail)
Subject: Re: Problem reading forms with perl
Organization: Newsfeeds.com http://www.newsfeeds.com 72,000+ UNCENSORED
Newsgroups. Instant access!!
*_'_=*{chr($b*$e)};*__=*{chr(1<<$e)};
_::_(r(e(k(c(a(H(__(l(r(e(P(__(r(e(h(t(o(n(a(__(t(us(J())))))))))))))))))))))))
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers
==-----
--
|Fidonet: UUCP 2:500/3.1
|Internet: UUCP@p1.f3.n500.z2.hccfido.hcc.nl
|
| Standard disclaimer: The views of this user are strictly his own.
------------------------------
Date: 12 Aug 1999 19:05:08 GMT
From: dalonso@u.washington.edu (Darwin O.V. Alonso)
Subject: code references to builtin functions
Message-Id: <7ov5t4$6t2$1@nntp6.u.washington.edu>
I want a perl script to evaluate the builtin perl function that
I give as a, command line argument. E.G.:
trig.p sin
evaluates sin at some predetermined value.
I can do it using eval, and the following snipit works:
...
$function = shift(@ARGV); #$ARGV[0] = "sin"
$f = eval "$function ($pi * ( 4/100) )","\n";
...
And, I can do it using code references if I write my own function:
...
$function = shift(@ARGV); #$ARGV[0] = "mysin"
$f = &$function_name($pi * ( 4/100) );
...
sub mysin {
my ($x) = shift @_;
sin($x);
}
However, I have not been able to use $ARGV[0] as a reference
to a builtin perl function (e.g. sin). How can I do that?
I.E., something like:
$function = shift(@ARGV); #$ARGV[0] = "sin"
$f = $function ($pi * ( 4/100) );
Thanks,
Darwin
------------------------------
Date: Thu, 12 Aug 1999 12:08:50 -0700
From: mikej <mikej@1185design.com>
Subject: get data from flat file
Message-Id: <37B31BC1.19954DAB@1185design.com>
Hey,
I have a log file full of data that my script attempts to read, parse
and display. When the user enters a text string into the form field and
submits the form to the script, the script should go through each line
of the data file looking for a match for the text string and then return
all the variables on the same line. The data file is formatted like
this:
client1|username1|password1
client2|username2|password2
client3|username3|password3
client4|username4|password4
if the person submitting the form enters "client3" then it should
display "username3" and "password3" for the results page. The problem is
it only works for the first line. Heres what I have for the main part of
the script:
$clientname = $file_form{'name'};
#extract username and password from password.log file
open(LOG, "password.log") || &error("Couldn't open log file \n\n$!");
@indata = <LOG>;
close(LOG);
foreach $line (@indata)
{
chomp($line);
($data_name, $data_username, $data_password) = split(/\|/, $line);
if ($data_name eq $clientname) {
$username = "$data_username";
$password = "$data_password";
}
}
#print results
print "Content-type:text/html\n\n";
print "<html><head><title>query results</title></head>\n";
print "<body bgcolor= \"#FFFFFF\">\n";
print "<B>Client:</B> $clientname<BR><BR>\n";
print "<B>Username:</B> $username<BR>\n";
print "<B>Password:</B> $password<BR>\n";
print "</body></html>\n";
Does anyone see anything wrong?
mike
------------------------------
Date: Thu, 12 Aug 1999 12:09:46 -0700
From: Makarand Kulkarni <makkulka@cisco.REMOVETHIS.com>
Subject: Re: List Files in a directory and search
Message-Id: <37B31BFA.9E6FA6C7@cisco.REMOVETHIS.com>
[
nerilius@my-deja.com wrote:
> I'm trying to write a program that searches a directory for a file. >If that file exists it returns true.
> This doesn't work:
> [some code snipped..]
> opendir(DIR, "/u60/gabeus/");
Check for errors from opendir().
> foreach $fir (readdir(DIR)) {
> push @array, $fir;
> }
> close(DIR);
OK. But your could have called readdir() in array context.
> foreach $f (@array) {
> if ($viles =~ /$f/) {
> $i=1;
> }
> }
What you are doing is checking whether the pattern in
$viles is present in the name of the file in $f. This
is not what you want. You should check for string equality.
Also you can jump out of the loop once $i is set to 1.
--
------------------------------
Date: Thu, 12 Aug 1999 12:41:58 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: List Files in a directory and search
Message-Id: <Pine.GSO.4.10.9908121235491.7774-100000@user2.teleport.com>
On Thu, 12 Aug 1999 nerilius@my-deja.com wrote:
> I'm trying to write a program that searches a directory for a file.
> If that file exists it returns true.
That sounds like the -e filetest to me.
> This doesn't work:
You'll have to be more specific than that; in what way does it fail to
meet your expectations?
> #!/usr/bin/perl
Use -w warnings; use 'use strict'.
> require "cgi-lib.pl";
This may not be the best way to do this; many people use a well-written
module.
> print " <form method=POST
> action=\"http://www.worldphase.com/cgi-bin/attack.cgi\"
> name=\"bigform\">";
You should probably be using a here-document, if in fact you need to do
this as you're doing it.
> opendir(DIR, "/u60/gabeus/");
Don't forget to check the return value from opendir.
> foreach $fir (readdir(DIR)) {
> push @array, $fir;
> }
> close(DIR);
>
> $i=0;
> foreach $f (@array) {
> if ($viles =~ /$f/) {
This is the hard way to do it. And, of course, this could crash your
program, if the value of $f isn't a valid pattern. But the /o modifier may
be a good idea, if that's what you really want. Still, I think you're
really wanting the -e filetest, after checking the form of the input, of
course. Or maybe you want to try creating the file, and complain if that
fails.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Thu, 12 Aug 1999 20:25:38 +0100
From: "Rob Sedgwick" <newsgroups@justinfashanu.demon.co.uk>
Subject: LWP
Message-Id: <934486251.20375.0.nnrp-13.d4e4e97b@news.demon.co.uk>
I wondered if anyone could pick up on an earlier thread I originated:
QuestionExchange <USENET@questionexchange.com> wrote in message
news:237qx@questionexchange.com...
> The question is unclear.
>
> What's the second library you're loioking for?
> What do you mean by 'provide'? Do you look where to download libraries
from or do you look for a free web host that will let you *use* perl CGI
csripts on their site?
>
> If you're just looking for the place to download LWP, you can get it from
http://www.linpro.no/lwp/
>
> If you need anything else perl-related, chances are you will find it at
CPAN (Comprehensive Perl Archive Network) site http://www.cpan.org
>
> There is CPAN search engine:
> http://theory.uwinnipeg.ca/search/cpan-search.html
>
I am not looking where to download the libraries from. My understanding is
that the libraries have to be compiled on the machine on which they are
present, i.e. I can't just stick them in mt CGI-BIN directory and they will
work. Is this correct? There are several web hosts that I know of who allow
you to use perl CGI scripts.
Rob
--
E-mail: rsedgwick@justinfashanu.demon.co.uk
Homepage: http://www.justinfashanu.demon.co.uk
Cockatiel Genetics: http://only.at/cockatiels
------------------------------
Date: 12 Aug 1999 20:01:15 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: Parse::RecDescent, optional subrules, and errors
Message-Id: <7ov96b$3g6$1@towncrier.cc.monash.edu.au>
rand@qualityic.com (Rand Bamberg) writes:
> How about an extension to <error> (<error!>, maybe)
> that would always force an error and disable pruning thereof?
Hmmmm. Unprunable errors. Not a bad thought.
>> Clearly the error pruning heuristics need another tweak.
>> I'll queue it in my ToDo file.
> And an impressive ToDo file it must be! ;-)
Yes, it's a nightmare:
* Grammar precompiler (nearly done!)
* Mechanism to trigger errors immediately (i.e. on resync)
* Improve error messages where optional subrules involved
* Omit pruning of "partial match" errors generated in optional subrules
* <fail> and <fail?> directives to instantly cause entire parse to fail
* %item for named items
* <score:...> directive to production selection criterion
* Mailing list
* Clean up interface (make truly OO)
* Improve code generation: produce smaller parsers
* Improve code generation: produce (much) faster parsers
* Implement common prefix extraction on productions of a single rule
* Inlining of simple (one item) subrules
* <atstart> and <atend> directives to anchor match
* <memoize> directive to specify per-rule memoization
* Lookbehind (?)
* Automatically insert <commit>s after common prefixes (?)
* Speed up parse with predictors (?)
* Non-insatiable repetitions (i.e. backtracking on: subrule(s) subrule)
* Parsimonious repetitions
* Handle left-recursion (preferably without rearranging grammar) (????)
* Achieve world domin^H^H^H^H^Hpeace.
:-)
> I'm looking very forward to your 2.0 release, and your book.
> ...Have you thought about setting up a mailing list for Parse::RecDescent?
See above. I'll probably brace Nat Torkington about it at TPC.
> It would be a convenient place to archive FAQs like this, at least, and
> spare you some cycles...
Both worthy aims, especially the latter ;-)
> Thanks again,
My pleasure,
Damian
------------------------------
Date: Thu, 12 Aug 1999 15:29:30 -0400
From: JP <Jeff.T.Parker@compaq.com>
Subject: Re: Perl Novice needs advice
Message-Id: <37B32099.A0E699CA@compaq.com>
hey -one step further --let's not forget that Winblows isn't the only OS to
run ActiveState Perl ...for instance, just two feet away from this NT server
is it's cousin, a NetWare 5 box running ActiveState Perl, also.
....just a plug for a commonly forgotten NOS....
Steve Linberg wrote:
> In article <37b2f111.25524051@news>, marcel.grunauer@lovely.net (Marcel
> Grunauer) wrote:
>
> > On Thu, 12 Aug 1999 01:52:09 GMT, slinberg@crocker.com (Steve Linberg)
> > wrote:
> >
> > >In article <37B20C75.32F7A3A9@mail.cor.epa.gov>, David Cassell
> > ><cassell@mail.cor.epa.gov> wrote:
> > >
> > >> Since you're on a PC already, I'll assume you have ActiveState
> > >> Perl.
> > >
> > >Arrgh! Why assume that PC eq "Windows"?
> > >
> > >Even if it's likely, let's not assume that. :)
> >
> > From the original post:
> >
> > X-Newsreader: Microsoft Outlook Express 5.00.2314.1300
> > X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
>
> Yeah, but that doesn't mean the machine posted from is the machine being
> referred to. ;)
>
> I know, I know, let's just drop it.
>
> --
> Steve Linberg, Systems Programmer &c.
> National Center on Adult Literacy, University of Pennsylvania
> Be kind. Remember, everyone you meet is fighting a hard battle.
> print 'Just Another Perl ' . $perl_hierarchy[(USER+EXPERT)/2];
------------------------------
Date: 12 Aug 1999 19:25:19 GMT
From: delcasti@cs.fsu.edu (Kent Delcastillo)
Subject: Perl vs. ASP: which is better?
Message-Id: <7ov72v$43l$1@news.fsu.edu>
I'm curious to know what everyone thinks. I expect a Perl bias since I'm
in the PERL newsgroup, but I'm interested to know why. I've learned a lot
of PERL and am now learning ASP, interested to hear peoples thoughts...
--
Kent Del Castillo
kent@kentd.com
------------------------------
Date: Thu, 12 Aug 1999 16:04:55 -0400
From: jerrad pierce <jerrad@networkengines.com>
Subject: Re: Perl vs. ASP: which is better?
Message-Id: <37B328E7.6DC6E739@networkengines.com>
You're comparing apples and oranges
ASP is an environment Perl is a language
You can compare Perl and VBScript or ASP and CGI but not Perl and ASP or CGI and VBScript.
I'll assume you mean ASP w/VBscript vs Perl CGI.
I do both, and they both have their uses.
Better yet, use PerlScript w/ ASP.
------------------------------
Date: Thu, 12 Aug 1999 19:51:05 GMT
From: loadc@my-deja.com
Subject: PTk
Message-Id: <7ov8j5$kdt$1@nnrp1.deja.com>
Hello-
I am having trouble putting PTk on my machine, I get:
:/usr/freeware/Tk800.015 [ 758 ] perl Makefile.PL
perl is installed in /usr/local/lib/perl5/5.00502/sys3k okay
PPM for perl5.00502
Test Compiling config/signedchar.c
Test Compiling config/Ksprintf.c
Test Compiling config/tod.c
Test Compiling -DTIMEOFDAY_TZ config/tod.c
Test Compiling -DTIMEOFDAY_NO_TZ config/tod.c
Test Compiling -DTIMEOFDAY_DOTS config/tod.c
DOTS gettimeofday()
Using -L/usr/lib/X11R3 to find /usr/lib/X11R3/libX11.so.1
Cannot find X include files via /include
Cannot find X include files anywhere at ./myConfig line 318.
BEGIN failed--compilation aborted at Makefile.PL line 19.
Is this a really simple error and I am just that inexperienced or
is it something more? I am guessing that the makefile is having trouble
finding my X include files, except that all of the files are in the
correct places, the script finds libX11.so.1, but I don't use /include.
Would a sym link work here? Thanks in advance for the help,
Thanks,
loadc
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Thu, 12 Aug 1999 19:35:02 GMT
From: Christopher Conway <chris_conway@my-deja.com>
Subject: Re: s/// and interpolation
Message-Id: <7ov7l6$jl3$1@nnrp1.deja.com>
In article <linberg-1208991151060001@ltl1.literacy.upenn.edu>,
linberg@literacy.upenn.edu (Steve Linberg) wrote:
> > Now a safety question: given this formulation, is their
> > anyway to force execution of malicious code? This is more
> > or less an academic matter, since I'm using this script
> > as an internal utility for myself and other coders.
>
> YES, it's easy. Just supply a substring that completes the regexp,
and
> then do anything you want. So, given the input:
>
> /; `rm -rf /`; #
>
> your $regexp string becomes
>
> $record =~ s/(\d{3})-(\d{2})-(\d{4})//; `rm -rf /`; #/
>
> And then your eval statement makes you very, very unhappy.
This is very clever. Thanks for pointing it out.
(It hadn't occured to me that the input could close
the s/// operator and go on to do what it pleased.)
> You should NEVER eval a string from user input. Even if you think
you're
> the only one using it. Or, do so at your own extreme peril. The best
> case is you'll be OK, the worst case is you'll lose everything. I
> wouldn't risk it, myself.
You're right. Just because I don't expect my users to
be malicious doesn't mean they can't be sloppy or stupid.
That leaves me wondering if this can be accomplished in
another way and I'll reiterate that it seems like it
should be doable in a more or less straightforward way.
Maybe Uri's aggravatingly oracular pointer will yield
some answers...
Chris
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: 12 Aug 1999 15:05:20 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Sesssion ID
Message-Id: <x7wvv06cr3.fsf@home.sysarch.com>
>>>>> "GB" == Greg Bacon <gbacon@itsc.uah.edu> writes:
GB> In article <x74si47u1n.fsf@home.sysarch.com>,
GB> Uri Guttman <uri@sysarch.com> writes:
GB> : >>>>> "TC" == Tom Christiansen <tchrist@mox.perl.com> writes:
GB> :
GB> : TC> for $value ($sec, $min, $hour, $mday) {
GB> : TC> $value = sprintf "%02d", $value;
GB> : TC> }
GB> :
GB> : sorry, tom, that is too obscure for even the most jaded perl hacker
GB> : (except you!). though it is cute code.
GB> Please point out the part or parts that are "too obscure".
it took me more than a few seconds to see that $value was both a rvalue
and an aliased lvalue. i have rarely seen that with the loop var of
for. so i call it obscure. my taste. and i posted alternatives which i
find clearer.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.
------------------------------
Date: 12 Aug 1999 19:24:13 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Sesssion ID
Message-Id: <7ov70t$afb$3@info2.uah.edu>
In article <x7wvv06cr3.fsf@home.sysarch.com>,
Uri Guttman <uri@sysarch.com> writes:
: >>>>> "GB" == Greg Bacon <gbacon@itsc.uah.edu> writes:
:
: GB> Please point out the part or parts that are "too obscure".
:
: it took me more than a few seconds to see that $value was both a rvalue
: and an aliased lvalue.
Rob Pike on style:
As a rule, if you find code containing many similar, complex
expressions that evaluate to elements of a data structure, judicious
use of pointers can clear things up. Consider what
if(goleft)
p->left=p->right->left;
else
p->right=p->left->right;
would look like using a compound expression for p. Sometimes it's
worth a temporary variable (here p) or a macro to distill the
calculation.
Yes, he's talking about C and pointers, but this wisdom applies to
Perl and aliases too.
: i have rarely seen that with the loop var of
: for. so i call it obscure.
That's a pretty bad criterion for obscurity.
: my taste. and i posted alternatives which i
: find clearer.
TMTOWTDI, but one person having to glance twice at a small snippet doth
not obscure code make.
Greg
--
Those who do not understand UNIX are condemned to reinvent it -- badly.
-- Henry Spencer
------------------------------
Date: 12 Aug 1999 13:26:24 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Sesssion ID
Message-Id: <37b31fe0@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
snowhare@long-lake.nihongo.org (Benjamin Franz) writes:
:Aggie, Tom and Uri write:
:
: "We can do it better. Or at least weirder."
: benjamin2: 10 wallclock secs ( 8.20 usr + 0.00 sys = 8.20 CPU)
: fl_aggie: 11 wallclock secs (10.45 usr + 0.03 sys = 10.48 CPU)
: original: 11 wallclock secs ( 9.64 usr + 0.00 sys = 9.64 CPU)
: tomc: 13 wallclock secs (12.25 usr + 0.00 sys = 12.25 CPU)
: uri1: 14 wallclock secs (13.48 usr + 0.00 sys = 13.48 CPU)
: uri2: 14 wallclock secs (12.36 usr + 0.01 sys = 12.37 CPU)
:
:As you can see, none of (Tom, Aggie and Uri's) proposals are faster than the
:_original_ code. I (of course ;) ) was able to improve on it slightly.
So what? Clarity, consistency, and deletion of redundancy
were my goal. These are much more important then a few nanosecond
here and there.
The highest virtue of the programmer is to seek out redundancy and factor
it out. To see the same thing repeated and repeated and repeated is
enough to make any programmer blanche. Every time I see the same thing
done again and again and again with varying variables I just want yank
that horrid crap right out of there and replace it with a subroutine or
a for() aliasing loop. You don't know how many times I've encountered
this kind of thing:
$this =~ s/^\s*//;
$that =~ s/^\s*//;
$more =~ s/^\s*//;
$stuff =~ s/^\s*//;
$here =~ s/^\s*//;
And just wanted to smack the guy. That should be:
for ($this, $that, $more, $stuff, $here) {
s/^\s*//;
}
Even this bugs me:
$w += $i;
$x += $i;
$y += $i;
$z += $i;
That would be more clearly expressed as:
for $num ($w, $x, $y, $z) {
$num += $i;
}
And let's not forget the scintillating:
for ( $scalar, @array, @hash{keys %hash} ) {
s/ ^ \s+ //sx;
s/ \s+ $ //sx;
}
I don't want seven and fifteen twelfths of something. I want eight and
a quarter of it. Factor out redundancies, for they are offensive to
the eye of the discerning and cautious programmer.
--tom
--
("I pray for") "The strength to change what I can, the inability to accept what
I can't, and the incapacity to tell the difference."
- Calvin
------------------------------
Date: 12 Aug 1999 15:35:23 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Sesssion ID
Message-Id: <x7u2q46bd0.fsf@home.sysarch.com>
>>>>> "BF" == Benjamin Franz <snowhare@long-lake.nihongo.org> writes:
BF> Aggie, Tom and Uri write:
BF> "We can do it better. Or at least weirder."
BF> return "$wkday, $mday-$month-$year ${hour}\:${min}\:${sec} GMT";
so why are you backwhacking the : in that string?
BF> sub benjamin2 {
BF> sprintf('%s, %02d-%s-%s %02d:%02d:%02d GMT',$wday,$mday,$mon,$year+1900,$hour,$min,$sec);
BF> }
and the problem spec never mentioned a full date string. using localtime
or spftime would be simpler and probably faster too. and any of us would
have used sprintf if that was the need. we were just padding 4 separate
scalar vars to 2 digits. very different.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.
------------------------------
Date: 12 Aug 1999 19:31:56 GMT
From: delcasti@cs.fsu.edu (Kent Delcastillo)
Subject: Re: Sesssion ID
Message-Id: <7ov7fc$43l$2@news.fsu.edu>
As far as I know, after you verify the users login & pass, you then assign
the client a session id ( a random string ). You then verify the session
id with each query instead of the user/passw. This is safer b/c you don't
have to pass the user/passw each time. Then you timeout the session id and
destroy it after a certain length of time of no activity.
Hope that helps, pardon the redundancy.
Troy Knight (flexit@flexit.eurobell.co.uk) wrote:
: Okay, I want to write a login program which asks for a login name and
: password and then keeps track of which user is using the script, someone
: told me to use session id's. I have been looking on the net for ages but
: can't find info on what session id's are and how to use them. Can anyone
: help?
:
: Troy
:
:
--
Kent Del Castillo
kent@kentd.com
------------------------------
Date: 12 Aug 1999 13:46:08 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Sesssion ID
Message-Id: <37b32480@cs.colorado.edu>
Rob's right.
Meanwhile, here's another standard idiom:
for $numstr (@numlist) {
$numstr = oct($numstr) if $numstr =~ /^0/;
}
Or course, we now have "numstr" four times. This too can offend.
for (@numlist) {
$_ = oct() if /^0/;
}
Suffices.
Here's one from Ram:3
# now random mungings to get their string parsable
for ($when) {
s/ (for|via) .*$//;
s/([+-]\d\d\d\d) \(\S+\)/$1/;
s/id \S+;\s*//;
}
And here's another from the same place:
# fix microseconds
for ($done[1], $start[1]) { $_ /= 1_000_000 }
And here's one from Ram:5
for ($prefix .= $line) { # build up more output
s/\d /| /;
s/[^|]/ /g;
}
And here's one from Ram:6
for (@libdirs = @bindirs) { s/bin/lib/ }
And then of course there's the infamous:
#!/usr/bin/perl
# bados -- tchrist@perl.com
#################################################
# redirect the point-and-drool masses elsewhere #
#################################################
for ($ENV{HTTP_USER_AGENT}) {
$quiplet = /Mac/ && 'm/Macintrash.html'
||
/Win(dows )?NT/ && 'e/evilandrude.html'
||
/Win|MSIE|WebTV/ && 'm/MicroslothWindows.html'
||
/Amiga/ && 'a/amoeba.html'
||
/IBM/ && 'i/IBM.html'
||
/Linux/ && 'l/Linux.html'
||
/HP-UX/ && 'h/HP-SUX.html'
||
/SunOS/ && 's/ScumOS.html'
||
/AIX/ && 'a/AIDX.html'
||
/SCO/ && 'o/OpenDeathTrap.html'
||
/VMS/ && 'v/VMS.html'
||
/OSF/ && 'f/FUDwars.html'
||
/BSD/ && 'b/BSD.html'
||
/OS\/?2/ && 'o/OS2.html'
||
/X11/ && '/u/Unix.html'
||
'a/AppendixB.html';
}
print "Location: http://www.wins.uva.nl/~mes/jargon/$quiplet\n\n";
Or even:
for ($^O) {
*struct_flock = do {
/bsd/ && \&bsd_flock
||
/linux/ && \&linux_flock
||
/sunos/ && \&sunos_flock
||
die "unknown operating system $^O, bailing out";
};
}
Yes, the do is there solely as a masthead. :-)
While the two lattermost examples are intentionally stylistic, the
point remains that if "for ($var)" isn't clear to you, you simply
aren't familiar with commmon perl idioms, and it might benefit you
to become such.
--tom
--
"When did you get so paranoid?"
"When they started plotting against me."
- The Paper
------------------------------
Date: Thu, 12 Aug 1999 14:32:51 -0500
From: Kevin Raison <raison@mc.net>
Subject: Re: Starnge DBI behavior
Message-Id: <37B32163.B21909EF@mc.net>
Given the typo corrections below, the odd behavior of fetchrow_arrayref is
still at issue.
On each iteration, it is reusing the same memory address for what should be a
different reference.
Kevin Raison wrote:
my @array;
my $sth = $dbh->prepare("select * from table") || die($dbh->errstr);
$sth->execute || die($dbh->errstr);
my $aref;
while($aref = $sth->fetchrow_arrayref) {
push(@array,$aref);
}
foreach(@array) {
print "$_->[0] : $_->[1]\n";
}
$sth = {};
or
$sth->finish;
--
Kevin Raison (raison@mc.net)
Senior Systems Administrator
MCnet
http://www.mc.net
------------------------------
Date: Thu, 12 Aug 1999 19:58:56 GMT
From: "Michael P. Reilly" <arcege@shore.net>
Subject: Re: Why use Perl when we've got Python?!
Message-Id: <4IFs3.1639$EG4.307155@news.shore.net>
Matt <mck@iag.net> wrote:
: On Thu, 12 Aug 1999 17:52:25 GMT,
: mcafee@waits.facilities.med.umich.edu (Sean McAfee) wrote:
:>To help me learn Python, I decided to rewrite some of my Perl scripts
:>in Python. The first script I chose for conversion was called "getfile";
:>it grabs a file via FTP and prints it on stdout.
: Did you finish the conversion? If so, it would be interesting to see
: the code to compare, for us who know no Python.
I do not know what Sean finally came up with after looking in the
standard library documentation, but this works:
import os # to call stty
import sys # to get arguments and stdout
import urllib # to get a url
# get the arguments (no error handling)
host, userid, file = sys.argv[1:]
# get the password from console
os.system('stty -echo')
password = raw_input('Password:')
os.system('stty echo')
# get an open socket to the remote file (again no error handling)
url = 'ftp://%s:%s@%s/%s' % (userid, password, host, file)
file = urllib.urlopen(url)
# copy the data to stdout
data = file.read()
sys.stdout.write(data)
The urllib hides the details of the various protocols (such as FTP)
from the user. (Although there is a bug where it cannot handle
absolute pathnames.)
-Arcege
------------------------------
Date: Thu, 12 Aug 1999 13:03:43 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Win32 Perl won't display HTML
Message-Id: <37B3289F.1F74D0A7@mail.cor.epa.gov>
stirling@banet.net wrote:
>
> >Well, it works fine with command level but it won't display HTML output on
> >web browser.
>
> Check to see if you use the following statement before any HTML output:
> print "Content-type:text/html\n\n";
^^
I think you forgot the space after the colon.
> Not having those lines would most definetly cause your script to bug,
> also if would help if you would give more specific error messages.
And remembering that space will ensure that this works for
all browsers, and not just those which are used to seeing
deformed HTML.
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Thu, 12 Aug 1999 19:21:52 GMT
From: churchylfem@my-deja.com
Subject: Yet Another Newbie Question - Or Did I Find a Bug?
Message-Id: <7ov6s6$j4c$1@nnrp1.deja.com>
Hello, all!
I'm new to perl, but not a new programmer. I recently needed to do
some stuff in DOS that was beyond the capability of batch (what
isn't?), and the client's environment did not have access to anything I
could use to develop with, so I downloaded active perl:
Characteristics of this binary (from libperl):
Locally applied patches:
ActivePerl Build 518
Built under MSWin32
Compiled at Jun 24 1999 13:14:00
@INC:
C:/Perl/lib
C:/Perl/site/lib
.
I'm running it on Win95 (french version, I can't read french).
I wanted to do a nested while loop. The first loop was to read the
contents of a directory, which worked fine. I put the results into
@dirlist. I then invoked a second while loop inside the first, and
searched each directory for a specific file, which I then opened and
performed a readline on. I set the while exit condition for each loop
to EOF like this (<OPENFILENAME>), which I presume is right, from the
perl nutshell book I bought.
Both loops appear to function normally, and to exit under the correct
conditions, with the exception that the inner loop is reading every
OTHER line in the file it opens, beginning with the second line. I
could not find a cause. By putting the readline outside the loop, I
could read every line with ease. Even inside of a single while loop
worked great. But inside of a nested while loop caused it to skip
every other line in every file it opened and read.
I finally solved the problem by hacking a very ugly solution - a for
loop nested inside the outer while loop, with a fake counter (1 to
2500), which is higher than any conditions it would meet, and forced
setting of the counter to 2501 when the line length equalled zero. I
know, I know, strictly amateur night, but hey, it was at night, and I
had a deadline.
But now that it's done, and it worked in hack mode, I'm wondering what
the heck I did wrong (or could there be a bug here). I'm betting it's
me.
Here's a code fragment of what I ended up doing:
opendir (DIRECTORY, "$INPUT_DRIVE")
|| warn "Could not open directory!\n";
@dirlist = grep /FLD/, readdir DIRECTORY;
closedir (DIRECTORY)
|| warn "Could not close directory!\n";
$counter = 0;
while (<@dirlist>) {
$FINAL_DRIVE = $dirlist[$counter];
$FINAL_DIRECTORY = $FINAL_DRIVE;
$FINAL_DIRECTORY =~ s/.FLD//g;
# print "You are inside the first loop, and the directory
is $FINAL_DRIVE\n";
open (BUBBA, "$INPUT_DRIVE/$FINAL_DRIVE/PVCSFOLD.PUB")
|| warn "Could not open input file!\n";
# print "The $dirlist[$counter]/pvcsfold.pub is open for
reading\n";
$counter++;
$counter_two = 0;
@newline = readline *BUBBA;
for ($x = 0; $x < 2500; $x++) {
# print "You are inside the second loop and the
counter = $counter.\n";
# print "The second counter = $counter_two.\n";
$HOWDY = $newline[$x];
if (($x > 2) && (length $HOWDY <=0)) {
$x=2501;
}
chomp $HOWDY;
$my_grep = grep /DOCUMENT/, $HOWDY;
if ($my_grep == 1){
@part = split /;/, $HOWDY;
$copy_from = $part[0];
$filename = $part[1];
$BACKSLASH = "\\";
$destination =
$DESTINATION_DRIVE . $BACKSLASH . $PROJECT_DIR . $BACKSLASH .
$FINAL_DIRECTORY;
$copy_from =~ s/
\[\DOCUMENT=/xcopy \/e\ /g;
$OUTPUT_LINE = $copy_from .
$BACKSLASH . $filename . " " . $destination . $BACKSLASH;
system $OUTPUT_LINE;
# print "$OUTPUT_LINE\n";
}
Please don't heckle me more than you have to, but here is what I
actually started with (which had the skipped line problem):
$DESTINATION_DRIVE = "C:\\MIGRATION_DIRECTORY";
# $PROJECT_NAME = "CDG_THEO.prj";
$PROJECT_NAME = "CDG_EVP.prj";
# $PROJECT_NAME = "CDG_DCA.prj";
# $PROJECT_NAME = "CDGESP.prj";
$PROJECT_DIR = $PROJECT_NAME;
$PROJECT_DIR =~ s/.prj//g;
$INPUT_DRIVE = "V:/LIB_PROJ/ADMPVCS/$PROJECT_NAME";
opendir (DIRECTORY, "$INPUT_DRIVE")
|| warn "Could not open directory!\n";
@dirlist = grep /FLD/, readdir DIRECTORY;
# @sorted_dirlist = sort (@dirlist);
$counter = 0;
while (<@dirlist>) {
$FINAL_DRIVE = $dirlist[$counter];
$FINAL_DIRECTORY = $FINAL_DRIVE;
$FINAL_DIRECTORY =~ s/.FLD//g;
print "You are inside the first loop, and the directory
is $FINAL_DIRECTORY\n";
open (INPUT, "$INPUT_DRIVE/$dirlist
[$counter]/PVCSFOLD.PUB")
|| warn "Could not open input file!\n";
print "The pvcsfold.pub is open for reading\n";
while (<INPUT>) {
$readline = readline *INPUT;
chomp ($readline);
print "$readline\n";
$my_grep = grep /DOCUMENT/, $readline;
if ($my_grep == 1){
@part = split /;/, $readline;
$copy_from = $part[0];
$filename = $part[1];
$BACKSLASH = "\\";
$destination =
$DESTINATION_DRIVE . $BACKSLASH . $PROJECT_DIR . $BACKSLASH .
$FINAL_DIRECTORY;
$copy_from =~ s/
\[\DOCUMENT=/xcopy \/e\ /g;
$OUTPUT_LINE = $copy_from .
$BACKSLASH . $filename . " " . $destination . $BACKSLASH;
# system $OUTPUT_LINE;
# print "$OUTPUT_LINE\n";
# print "$copy_from";
# print "\\";
# print "$filename";
# print " ";
# print "$destination\n";
}
$counter++;
}
}
closedir (DIRECTORY)
|| warn "Could not close directory!\n";
Any and all help would be appreciated!
Thanks,
Churchy LaFemme
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 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.
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" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. 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" from
almanac@ruby.oce.orst.edu.
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 487
*************************************