[19034] in Perl-Users-Digest
Perl-Users Digest, Issue: 1229 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 2 09:05:53 2001
Date: Mon, 2 Jul 2001 06:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <994079110-v10-i1229@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 2 Jul 2001 Volume: 10 Number: 1229
Today's topics:
Re: anonymous subroutines - why? <m.grimshaw@salford.ac.uk>
Re: anonymous subroutines - why? <goldbb2@earthlink.net>
Re: cgi posting to another cgi (David H. Adler)
Re: cgi posting to another cgi <goldbb2@earthlink.net>
check for file locking capabilities <tcr@gbf.de>
chmod xxx > where to put the command? <osttim@hotmail.com>
Counting occurences of a character <KEEPYOURgreywolf_pnwSPAM@snotmail.com>
Re: Counting occurences of a character <krahnj@acm.org>
Re: Counting occurences of a character (Logan Shaw)
Cryptographic Service Provider =?iso-8859-1?Q?f=FCr?= C <ack@ivu.de>
Re: Cryptographic Service Provider =?iso-8859-1?Q?f=FCr <ack@ivu.de>
Re: Cryptographic Service Provider =?iso-8859-1?Q?f=FCr <Deneb.Pettersson@lmf.ericsson.se>
efficient change file with locking (2) <twanGEENSPAM@twansoft.com>
Re: FAQ 9.15: How do I decode a CGI form? newbie ?s <"goodrow"@opencity. com>
Re: FAQ 9.15: How do I tell lies about decoding a CGI f (David H. Adler)
Re: FAQ 9.15: How do I tell lies about decoding a CGI f (David H. Adler)
Help Win32 and GetLastError <jm@comcen.com.au>
Re: inline average <bigrich318@yahoo.com>
Re: inline average <bigrich318@yahoo.com>
Re: limiting cgi input from specific IP's <m.grimshaw@salford.ac.uk>
Re: New babies to Perl - FREE Documentation Require (Logan Shaw)
On The Brink.... <cro@freeallangels.com>
Re: Open or Die - is die the only choice? (Rafael Garcia-Suarez)
Re: Problem using "*" in System(...) command <ayamanita.nospam@bigfoot.com>
Query: PERL v.s. Perl ==> What's the difference??? (codeslayer)
Re: Query: PERL v.s. Perl ==> What's the difference?? <krahnj@acm.org>
Re: Query: PERL v.s. Perl ==> What's the difference?? <pne-news-20010702@newton.digitalspace.net>
Re: Re:FAQ 9.15: How do I tell lies about decoding a CG <joehecht@code4sale.com>
Re: read/write ksh env array in Perl? <gnarinn@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 02 Jul 2001 11:10:01 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: Re: anonymous subroutines - why?
Message-Id: <3B404879.1002ED71@salford.ac.uk>
nobull@mail.com wrote:
>
> Mark Grimshaw <m.grimshaw@salford.ac.uk> writes:
>
> > [...] I've got a simplified version just for test purposes followed by a
> > 'standard' example. Despite the fact that Ex 2 requires less typing, is
> > there an advantage to using Ex 1 or am I just being perverse for such a
> > simple script?
>
> I must admit I'm a bit bemused by this. You appear to say you've taken
> a bit of code that uses anonymous subroutines and simplified it to the
> point where it does nothing usesful and is simply an example of how
> anonymous subroutines work. You then ask if there's any advantage in
> this code in using anonymous subroutines!? Well... if you didn't what
> would be it's function?
>
(If I didn't supply an example (no matter how simple), I'd probably be
asked to supply the code.)
I'm asking a general question on the usefulness of anonymous subroutines
possibly combined with coderefs. In the way I've used it, would, for
example, calling the coderef many times be more efficient than calling a
subroutine directly many times? i.e. what are the advantages to
anonymous subroutines?
------------------------------
Date: Mon, 02 Jul 2001 08:50:39 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: anonymous subroutines - why?
Message-Id: <3B406E1F.1B79ADA2@earthlink.net>
Mark Grimshaw wrote:
>
> nobull@mail.com wrote:
> >
> > Mark Grimshaw <m.grimshaw@salford.ac.uk> writes:
> >
> > > [...] I've got a simplified version just for test purposes
> > > followed by a 'standard' example. Despite the fact that Ex 2
> > > requires less typing, is there an advantage to using Ex 1 or am I
> > > just being perverse for such a simple script?
> >
> > I must admit I'm a bit bemused by this. You appear to say you've
> > taken a bit of code that uses anonymous subroutines and simplified
> > it to the point where it does nothing usesful and is simply an
> > example of how anonymous subroutines work. You then ask if there's
> > any advantage in this code in using anonymous subroutines!? Well...
> > if you didn't what would be it's function?
> >
>
> (If I didn't supply an example (no matter how simple), I'd probably be
> asked to supply the code.)
> I'm asking a general question on the usefulness of anonymous
> subroutines possibly combined with coderefs. In the way I've used it,
> would, for example, calling the coderef many times be more efficient
> than calling a subroutine directly many times? i.e. what are the
> advantages to anonymous subroutines?
The difference is not in efficiency, but in terms of readability and the
fact that an anonymous sub doesn't go into any symbol table.
Consider if you have a complicated function for find (from File::Find).
Which is nicer looking:
sub wanted {
....
}
@results = find( \&wanted, $path );
Or:
@results = find( sub {
....
}, $path );
Further, consider when you have a number of different find calls, with
different subs... you can't name all the subs "wanted", can you?
Lastly, when you need a closure, an anonymous sub is the best (only?)
way.
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: 2 Jul 2001 05:23:11 GMT
From: dha@panix.com (David H. Adler)
Subject: Re: cgi posting to another cgi
Message-Id: <slrn9k019v.qdb.dha@panix2.panix.com>
In article <Xns90CF8D9E31403dragnetinternalysisc@207.35.177.134>, Marc
Bissonnette wrote:
> yes. You'll have to excuse me for (still) using cgi-lib.pl, since I've just
> never gotten around to learning cgi.pm
As someone pointed out elsewhere, the answer probably lies in LWP,
rather than CGI, but...
cgi-lib.pl (unless I missed a meeting :-) hasn't been fully maintained
for quite some time. CGI.pm is in current development/maintenance.
You might want to look into using CGI.pm instead of cgi-lib.pl, with
the former's cgi-lib compatability option, so that you're using a
current module, but without the need for heavy modification to the
code you have (even though you may want to look into changing that as
time goes on).
Just a suggestion.
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
They would have done better with an axe!
- George Westinghouse on the first electric chair demo
------------------------------
Date: Mon, 02 Jul 2001 09:01:21 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: cgi posting to another cgi
Message-Id: <3B4070A1.22235337@earthlink.net>
David H. Adler wrote:
>
> In article <Xns90CF8D9E31403dragnetinternalysisc@207.35.177.134>, Marc
> Bissonnette wrote:
>
> > yes. You'll have to excuse me for (still) using cgi-lib.pl, since
> > I've just never gotten around to learning cgi.pm
>
> As someone pointed out elsewhere, the answer probably lies in LWP,
> rather than CGI, but...
>
> cgi-lib.pl (unless I missed a meeting :-) hasn't been fully maintained
> for quite some time. CGI.pm is in current development/maintenance.
That's because cgi-lib.pl is complete, and bug free. AFAIK, all the
bugs in it have been found. It needs no maintenance.
> You might want to look into using CGI.pm instead of cgi-lib.pl, with
> the former's cgi-lib compatability option, so that you're using a
> current module, but without the need for heavy modification to the
> code you have (even though you may want to look into changing that as
> time goes on).
If cgi-lib is what you're used to, I would advise you continue using it,
*but* the instance that you need to use modules (specifically, if you
need to call cgi functions from outside of package main::), switch to
using CGI.pm with the qw(:cgi-lib) compatability option. As they say,
if it aint broke, don't fix it.
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Mon, 02 Jul 2001 14:46:13 +0200
From: Torsten Crass <tcr@gbf.de>
Subject: check for file locking capabilities
Message-Id: <3B406D15.2A138CFC@gbf.de>
Hi,
does anyone know how one can determine if the operating system a script
is runnung on supports file locking - without causing the program to
die? (Specifically, I have a script which is supposed to run under
Linux, WinNT and Win98, but since Win98 doesn't have flock implemented,
the script should just skip the corresponding lines. Can't use $^O to
see if the script is condemned to run under Win98 since $^O doesn't
distinguish between the 32bit-Windowses...)
Thanx -
Torsten
---------------------------------------------------------------------
Dr. rer. nat mailto:torsten.crass@gbf.de
Torsten Crass visit me at http://home.comlink.org/tcrass
- Biochemist -
Research Group Bioinformatics
GBF (Gesellschaft fuer
Biotechnologische Forschung mbH) private:
Mascheroder Weg 1 Ratsbleiche 9
D-38124 Braunschweig 38114 Braunschweig
Fon: +49 (0)531-6181-460 Fon: 0531-3489709
Fax: +49 (0)531-6181-266 mailto:t.crass@comlink.org
---------------------------------------------------------------------
------------------------------
Date: Mon, 02 Jul 2001 10:10:55 GMT
From: tost <osttim@hotmail.com>
Subject: chmod xxx > where to put the command?
Message-Id: <B766154F.958B%osttim@hotmail.com>
Hi,
I'm not a real codeman, but I'm trying, I'm trying..
I'm installing WWWBoard (Matt's) on a server, and something is not clear to
me about the read/write/execute command:
I understand the idea of the chmod-command, but where exactly do I put it?
In the .pl or .cgi-file? Just right on top?
tnx for your time,
tost
------------------------------
Date: Mon, 02 Jul 2001 05:13:24 GMT
From: Greg Wolf <KEEPYOURgreywolf_pnwSPAM@snotmail.com>
Subject: Counting occurences of a character
Message-Id: <MPG.15a9a2fbf34485229898fa@news.earthlink.net>
I'm using Perl 5.6 to analyze an input file and use the information from
it to build an output file. The input file and the output file each
consists of a series of "\n" terminated lines, and each line is a record
in a comma-delimited database.
I'm using a while() statement to allow me to read one line from the
input file, and massage it into the form I need for the output file,
then read the next line, and so on...
One of the goals is to have each record in the output file have the same
number of fields. If there are any missing fields they will be at the
end of the record, and can be represented by commas followed by no
character. In other words,
I need 9 commas per line.
If there are 9 commas, I will append 0 commas to the end of the line.
If there are 8 commas, I will append 1 comma to the end of the line.
If there are 7 commas, I will append 2 commas to the end of the line.
and so on....
How do I determine how many commas are in each line in the input file?
As always, thank you in advance.
--
Greg Wolf
------------------------------
Date: Mon, 02 Jul 2001 05:31:27 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Counting occurences of a character
Message-Id: <3B40077C.4297E31@acm.org>
Greg Wolf wrote:
>
> I'm using Perl 5.6 to analyze an input file and use the information from
> it to build an output file. The input file and the output file each
> consists of a series of "\n" terminated lines, and each line is a record
> in a comma-delimited database.
>
> I'm using a while() statement to allow me to read one line from the
> input file, and massage it into the form I need for the output file,
> then read the next line, and so on...
>
> One of the goals is to have each record in the output file have the same
> number of fields. If there are any missing fields they will be at the
> end of the record, and can be represented by commas followed by no
> character. In other words,
>
> I need 9 commas per line.
> If there are 9 commas, I will append 0 commas to the end of the line.
> If there are 8 commas, I will append 1 comma to the end of the line.
> If there are 7 commas, I will append 2 commas to the end of the line.
> and so on....
>
> How do I determine how many commas are in each line in the input file?
while ( <DATA> ) {
chomp;
my $count = tr/,//;
$_ .= ',' x ( 9 - $count ) if $count < 9;
print "$_\n";
}
__DATA__
a,b,c,d,e,f,g,h
a,b,c,d,e,f,g,h,i,j
a,b,c,d,e,f,g,h,i
a,b,c,d,e,f,g,h
John
--
use Perl;
program
fulfillment
------------------------------
Date: 2 Jul 2001 00:49:46 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Counting occurences of a character
Message-Id: <9hp21q$qaj$1@charity.cs.utexas.edu>
In article <MPG.15a9a2fbf34485229898fa@news.earthlink.net>,
Greg Wolf <KEEPYOURgreywolf_pnwSPAM@snotmail.com> wrote:
>One of the goals is to have each record in the output file have the same
>number of fields. If there are any missing fields they will be at the
>end of the record, and can be represented by commas followed by no
>character. In other words,
>
>I need 9 commas per line.
>If there are 9 commas, I will append 0 commas to the end of the line.
>If there are 8 commas, I will append 1 comma to the end of the line.
It would probably be easier to create the output by using join.
If some of the fields don't have values, then set those fields
to the empty string. An example:
$foo = "abc";
$bar = "def";
print join (",", $foo, $bar), "\n";
$foo = "abc";
$bar = "";
print join (",", $foo, $bar), "\n";
$foo = "";
$bar = "def";
print join (",", $foo, $bar), "\n";
This prints:
abc,def
abc,
,def
Hope that helps.
- Logan
--
my your his her our their _its_
I'm you're he's she's we're they're _it's_
------------------------------
Date: Mon, 02 Jul 2001 09:24:35 +0200
From: Ulrich Ackermann <ack@ivu.de>
Subject: Cryptographic Service Provider =?iso-8859-1?Q?f=FCr?= Chipkarten?
Message-Id: <3B4021B3.9D9CEBD3@ivu.de>
Hallo Alfred,
ich habe bis März 2001 noch bei ORGA gearbeitet und Dich damals mit
Fragen zur MICARDO 2.0 Karte gelöchert. Wie Du an der Signatur erkennen
kannst, bin ich jetzt bei IVU in Berlin tätig.
Wir beschäftigen uns mit digitalen Signaturen und bräuchten eine
Provider Implementierung für Chipkarten. Hat ORGA so etwas? Unter
welchen Bedingungen kann man diese Implementierung bekommen?
Falls Du nicht der richtige Ansprechpartner dafür bist: An wen kann ich
mich mit dieser Frage wenden?
Viele Grüße, Ulrich
--
Dipl. Phys. Ulrich Ackermann
Senior Developer
IVU Traffic Technologies AG
Telefon: +49.30.85 906-449, mailto: ack@ivu.de
------------------------------
Date: Mon, 02 Jul 2001 12:51:41 +0200
From: Ulrich Ackermann <ack@ivu.de>
Subject: Re: Cryptographic Service Provider =?iso-8859-1?Q?f=FCr?= Chipkarten?
Message-Id: <3B40523D.9ED2DB4@ivu.de>
Ulrich Ackermann wrote:
Sorry, was not ment to be sent here :-(
Ulrich
--
Dipl. Phys. Ulrich Ackermann
Senior Developer
IVU Traffic Technologies AG
Telefon: +49.30.85 906-449, mailto: ack@ivu.de
------------------------------
Date: Mon, 02 Jul 2001 15:31:51 +0300
From: Deneb Pettersson <Deneb.Pettersson@lmf.ericsson.se>
Subject: Re: Cryptographic Service Provider =?iso-8859-1?Q?f=FCr?= Chipkarten?
Message-Id: <3B4069B7.21C1A007@lmf.ericsson.se>
no shit :)
------------------------------
Date: Mon, 02 Jul 2001 10:14:50 +0200
From: Twan Kogels <twanGEENSPAM@twansoft.com>
Subject: efficient change file with locking (2)
Message-Id: <6va0kt4og752fc8iervc5ruacfhokqkliq@4ax.com>
A couple weeks ago i had posted a message in this newsgroup about
"efficient change file with locking"
(<kp6eitsmbdp2qdkaofdae3cipj2l98euam@4ax.com>).
I got very helpfull replies, that resulted in the following code:
----
$file="test.txt";
$old = $file;
$new = "$file.tmp.$$";
$bak = "$file.orig";
open(OLD, "+< $old")||&OpenError("can't open $old: $!");
open(NEW, "> $new")||&OpenError("can't open $new: $!");
if($use_lock==1)
{
flock(OLD, 2);
flock(NEW, 2);
}
while (<OLD>)
{
print NEW "test: ".$_;
}
if($use_lock==1)
{
rename($old, $bak)||&OpenError("can't rename $old to $bak:
$!");
rename($new, $old)||&OpenError("can't rename $new to $old:
$!");
}
close(OLD);
close(NEW);
if($use_lock==0)
{
rename($old, $bak)||&OpenError("can't rename $old to $bak:
$!");
rename($new, $old)||&OpenError("can't rename $new to $old:
$!");
}
-----
(I set $use_lock to 0 when i test it on my local machine)
But after some time the locking functions doesn't appear to work, i
sometimes get a totally empty file.
As said in the last message my script sometimes get more then 5 hits
per second.
Does somebody knows if there is a problem/error with the above code?
Best regards,
Twan
------------------------------
Date: Mon, 02 Jul 2001 04:28:14 -0400
From: Jason Goodrow <"goodrow"@opencity. com>
Subject: Re: FAQ 9.15: How do I decode a CGI form? newbie ?s
Message-Id: <9hpb3r$ngp$1@news.panix.com>
Newbie with some non-flamewar questions -
I've had trouble with CGI.pm and ended up rolling my own for instances
where I didn't want to de-url-encode input.
(programing for Macromedia Flash input / output)
This FAQ has given me some (probably healthy) parinoia - a my beginners
instinct says continue rolling my own rather than study CGI.pm to cover
my code.
You'll see a lot of CGI programs that blindly read from STDIN the
number
of bytes equal to CONTENT_LENGTH for POSTs, or grab QUERY_STRING for
decoding GETs. These programs are very poorly written.
Guilty as charged.
They typically forget to check the return value of the read()
system call, which is a cardinal sin.
---any more info here?
They don't handle HEAD requests.
or here --- ?
They don't handle multipart forms used for file uploads. They don't
deal
with GET/POST combinations where query fields are in more than one
place. They don't deal with keywords in the query string.
These are all issues I haven't been addressing and I'm sure are lurking
to confuse the issue during some database breakdown. I'm going to
re-read the RFCs but can anyone point me at more knowledge?
Thanks in advance
goodrow@panix.com
------------------------------
Date: 2 Jul 2001 05:02:14 GMT
From: dha@panix.com (David H. Adler)
Subject: Re: FAQ 9.15: How do I tell lies about decoding a CGI form?
Message-Id: <slrn9k002m.qdb.dha@panix2.panix.com>
In article <3B3F6188.A4FE1FBB@stomp.stomp.tokyo>, Godzilla! wrote:
> "David H. Adler" wrote:
>
>> In article <3B3F3FEB.133FD97C@stomp.stomp.tokyo>, Godzilla! wrote:
>> > PerlFAQ Server wrote:
>
>> >> How do I decode a CGI form?
>
>> >> You use a standard module, probably CGI.pm. Under no circumstances
>> >> should you attempt to do so by hand!
>
>
>> > (snipped blatant idiocy)
>
>> > This specific FAQ ranges from mule manure to idiocy to outright lies.
>
>> > Posting this type of mule manure, posting this type of deceit, is
>> > not only a display of a lack of professionalism, it is also a display
>> > of highly unethical behavior.
>
>> > This is a document clearly written by a deceitful blithering idiot
>> > and appears to me to be a deliberate troll article.
>
>> > Interesting to note this name, PerlFAQ Server, is being used to
>> > impotently legitimize troll articles, much in the same manner
>> > Tad McClellan attempts to legitimize his fake newsgroup FAQ.
>
>> I'd find it more "interesting" if you would indicate what you think is
>> wrong with it, rather than just saying that it is "a deliberate
>> troll article".
>
>
> It is of no surprise both your reading comprehension skills and
> your Perl skills are such you cannot surmise truth for yourself.
How can I surmise your position when you refuse to give it?
The article covered a number of points. You make it quite unclear which
you object to. Given your history, I would imagine that you certainly
object to the intitial suggestion of CGI.pm. The article then goes on to
explain why the author considers not doing so to be a bad idea. Are the
pitfall listed things that you are in favor of? Do you think that
dealing with a HEAD request is an inherently bad thing, for instance?
Interesting that you make a wholly vague, provocative statement, then
when someone asks you for clarification you insult their abilities.
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
Linguists don't know much, but they do know that nobody can succeed in
telling people at large how to speak. - Larry Wall
------------------------------
Date: 2 Jul 2001 05:12:42 GMT
From: dha@panix.com (David H. Adler)
Subject: Re: FAQ 9.15: How do I tell lies about decoding a CGI form?
Message-Id: <slrn9k00ma.qdb.dha@panix2.panix.com>
In article <1evvts5.17v4blwgysav4N%tony@svanstrom.com>, Tony L. Svanstrom wrote:
> David H. Adler <dha@panix.com> wrote:
>
>> I'd find it more "interesting" if you would indicate what you think is
>> wrong with it, rather than just saying that it is "a deliberate
>> troll article".
>
> "Godzilla" is the troll, but besides that...
If that was what I was trying to say, I wouldn't have responded at all.
Historically, such a response to Godzilla leads to a "you're a troll"
"no, you're a troll" exchange that I find rather pointless.
I try only to respond to her when I see an actual point that can be
discussed logically. In this case, the dismissal of the advice in the
faq with no reason behind it. Sadly, despite asking a single, fairly
simple, question, I wound up being insulted anyway.
As a matter of fact, your comment seems to back up what I would guess is
Godzilla's complaint. My response to your comment is that it is not (as
I understand it from many whose opinion I respect rather more than my
own on this subject) quite so easy as many imagine it to be. Even if it
is, rewriting code that is already easily available to you (and tested
much more thoroughly than you will ever be able to test it) seems, to
me, to be a relatively wasteful activity.
If you *really* know what you're doing, you'll know that the admonition
is not there for you.
my $cents = 2.00;
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
Perhaps it IS a good day to Die! I say we ship it!
- a selection from "If Klingons developed software"
------------------------------
Date: Wed, 27 Jun 2001 01:09:04 -0700
From: Jason M <jm@comcen.com.au>
Subject: Help Win32 and GetLastError
Message-Id: <3B3994A0.DF38793@comcen.com.au>
Hello,
I need to execute a Visual Basic 6 program (standard exe) through Perl.
The VB program throws out runtime errors using the Win32 API
SetLastError.
I'm using the Win32 extension of Perl to enable access of Win32 API ie
use Win32;
use Win32::Process
BUT I'm unable to grab the error generated by the VB6 exe. Obviously,
the GetLastError call from Perl is looking at the Perl thread. How can
I access the VB thread to get the error thrown from the VB executable.
Thanks.
Jason
------------------------------
Date: Mon, 2 Jul 2001 05:11:28 -0500
From: "Rich" <bigrich318@yahoo.com>
Subject: Re: inline average
Message-Id: <tk0i85ild28u5b@corp.supernews.com>
"David Frauzel" <nogard@gnosrehtaew.ten> wrote in message
news:9ho2ub$rvu$1@news.aros.net...
> Thanks everyone.
>
> Looks as though the concensus is there are two ways, more or less, to get
it
> done. One is to tweak at the mechanics behind hashes themselves (with tie
> tricks); but for some reason that makes me queasy. It feels like changing
> the Laws of Physics just to get 1 and 1 to equal 3. ;} I know, I know,
> picky picky. Beggars choosers. All that. I am grateful for the examples,
> it's something I know I'll want to use eventually.
It's not really tweaking the mechanics of the hash. The example I gave tied
the hash value because you specified the use of a hash value. There could
just as easily been a $values_average scalar which could have produced the
same output.
use Average; #"Average" code from previous post
my %values = (
red => 5.0,
orange => 4.0,
yellow => 5.5,
);
my $values_average;
tie ($values_average, "Average", \%values);
print "The average is $values_average"; #prints 4.83
Or, you could also copy the object to access methods from the "Average"
class.
$object = tie ($values_average, "Average", \%values);
print "The average is $values_average"; # same as before
Or, you can access the methods directly.
my $avg = $object->FETCH();
print "The average is $avg"; #$avg is 4.83
>
> The second method looks more intriguing (maybe I'm just mystical like
that),
> where the end goal is to be able to write something like:
>
> > print "The average is ".$values{average}->()."\n\n"; #prints 4.83
>
> (Or if I want to future-proof myself for 6, I guess that would be
> "$values{average}.()"? That doesn't sound right...)
Also:
&{ $values{average} }()
$values{average}() # Perl 5.6+
>
> ... and make the value of {average} a sub.
Rather, a reference to a sub or an anonymous sub.
my %Functions = (
count => sub { $num++; &dosomethingwith($num) },
mycode => \&some_sub($var),
showname => sub { print "Hello $name" }
);
This hash of functions could then be used:
&{ $Functions{count} }() if $q->param('count');
if ($var) { $Functions{mycode}() } #Perl 5.6+
print &{ Functions{showname} }() if $name;
Or,
&{ Functions{$command} }() if exists Functions{$command};
>not quite OOP (like in Java),
tie would be the OO approach.
>not
> quite an inline function (like in C)...?
Not quite, but close.
my $inline_function = sub { return $_[0] * $_[1] };
my $total = &{ $inline_function }(3, 4); #multiply 3 by 4
print $total; # prints 12
>
> Again, thanks for all the advice. It was esoteric, I'm not failing any
> homework here, and it's fun to "learn something new every day". :)
>
> Vive le TMTOWTDI!
Amen.
Rich
------------------------------
Date: Mon, 2 Jul 2001 06:05:14 -0500
From: "Rich" <bigrich318@yahoo.com>
Subject: Re: inline average
Message-Id: <tk0lb388ag6g78@corp.supernews.com>
%$#@! typos.
print &{ Functions{showname} }() if $name;
Or,
&{ Functions{$command} }() if exists Functions{$command};
should be:
print &{ $Functions{showname} }() if $name;
Or,
&{ $Functions{$command} }() if exists $Functions{$command};
Rich
------------------------------
Date: Mon, 02 Jul 2001 10:57:21 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: Re: limiting cgi input from specific IP's
Message-Id: <3B404581.4F0FBC29@salford.ac.uk>
Laszlo Gerencser wrote:
> > > > Is it possible to limit some perl/cgi scripts so that they can only be run from
> > > > certain ip addresses?
> >
> > > Your script could read the remote_host() environment variable and then execute or
> > > exit based on what it finds. Read the docs for CGI.pm for details.
> >
> > Many local servers have remote host name lookup disabled for
> > efficiency. Just as many remote servers do not provide a
> > host name. Caution is advised pertaining to reliance upon
> > a host name for critical program operations.
> >
> > Godzilla!
> You have right. The env. var REMOTE_ADDR what he needs. This is the IP
> address of the client (as specified by the CGI 1.0/1.1)
>
<snip>
I've read somewhere that REMOTE_ADDR may not be the IP of the client but
possibly the IP of any proxy servers the client passes through. I may
be wrong.
------------------------------
Date: 2 Jul 2001 00:37:59 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: New babies to Perl - FREE Documentation Require
Message-Id: <9hp1bn$pgf$1@charity.cs.utexas.edu>
In article <9holud$437$1@dahlia.singnet.com.sg>,
Kelvin Wong <kvwong@singnet.com.sg> wrote:
>I'm a new babies in Perl Programming and does anyone know where can i get
>the FREE documentation of learning Perl Programming?
Well, the perl distribution should come with lots of documentation.
Try typing "perldoc perl".
There is also some documentation on http://www.perl.com/ , although
a lot of it is the same as what you've already got on your system.
- Logan
--
my your his her our their _its_
I'm you're he's she's we're they're _it's_
------------------------------
Date: Mon, 2 Jul 2001 12:23:25 +0100
From: "Cro" <cro@freeallangels.com>
Subject: On The Brink....
Message-Id: <9hplfh$k0b$1@plutonium.btinternet.com>
Hello Prospective help,
I don't know where to turn - I can't sleep at night - Please feel my
frustration! I have almost completed a very complex (or so I think) script
written in Perl. To complete it I need to do something that seems very
simple. I will try and explain it as fully as I can.
My script ranks sites.
Information is stored about each site on the list in a .dat file, including
it's current position, name and URL.
These 'member files' are stored in a directory called 'members' (named
1.dat, 2.dat 3.dat.....) where each site has it's own file.
I would like to print the names of the site ranked first, second and third.
Also, when these names are clicked upon I would like them to hyperlink to
the appropriate site.
Extra Information:
Within a member's file;
@data[3] = Current Position
@data[4] = SiteName
@data[5] = SiteURL
To overcome this problem I will need 6 new variables:
$1SiteName - Stores Site Ranked First Name
$1SiteURL - Stores Site Ranked First URL
$2SiteName - Stores Site Ranked Second Name
$2SiteURL - Stores Site Ranked Second URL
$3SiteName - Stores Site Ranked Third Name
$3SiteUR - Stores Site Ranked Third URL
I am unfamiliar with the syntax so the following attempt at the solution is
basically an algorithm.
sub find_site_info {
Open and read Member files
Where @data[3]=1
@data[4]=$1SiteName
@data[5]=$1SiteURL
Where @data[3]=2
@data[4]=$2SiteName
@data[5]=$2SiteURL
Where @data[3]=3
@data[4]=$3SiteName
@data[5]=$3SiteURL
Close Member files
}
How can I write the code in perl to perform the above algorithm?
Once it is done I will easily be able to write:
The top site is: <a href="$1SiteURL">$1SiteName</a>
The 2nd site is: <a href="$2SiteURL">$2SiteName</a>
The 3rd site is: <a href="$3SiteURL">$3SiteName</a>
Please make my day, week and month all in one!
Best regards,
Paul
------------------------------
Date: 2 Jul 2001 10:32:38 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Open or Die - is die the only choice?
Message-Id: <slrn9k0jel.hak.rgarciasuarez@rafael.kazibao.net>
Tony Curtis wrote in comp.lang.perl.misc:
} >> On Sat, 30 Jun 2001 15:44:02 GMT,
} >> Gary <gamtci@mpinet.net> said:
}
} > Every book I have shows "open or die". Isn't there any
} > other way to determine if the open succeeded? I have
} > been checking for existence using if (-f $file) first,
} > but I'd still rather know the open succeeded.
}
} That's not recommended because the file could disappear
} between the -f and a subsequent open (race condition).
Or because the file exists but is not readable by the script; or because
there is not enough memory left, and the OS refuses to create a new
filehandle.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Mon, 02 Jul 2001 04:42:28 GMT
From: Akira Yamanita <ayamanita.nospam@bigfoot.com>
Subject: Re: Problem using "*" in System(...) command
Message-Id: <3B3FFBAB.37BE6B3D@bigfoot.com>
Joe Smith wrote:
>
> You typed "mycopy.pl MyFile*", but what the program saw was something like
> "mycopy.pl MyFile.1 MyFile.2". That's because the shell expanded the
> wildcards; your perl program never saw the asterisk.
Yup, so "mycopy.pl MyFile\*" will work fine from the shell.
Since he's just passing it as an argument to a system call, I don't
think there's a reason to do the expansion.
------------------------------
Date: 1 Jul 2001 21:48:44 -0700
From: weedmonster_99@yahoo.com (codeslayer)
Subject: Query: PERL v.s. Perl ==> What's the difference???
Message-Id: <4b459565.0107012048.3522f728@posting.google.com>
To Whoever Knows the Answer:
I do not understand why so many of these posts where someone says
"PERL", end up with some snyd comment to the effect of "its 'Perl' not
'PERL'". Firstly, that logic doesn't make sense. Acronyms are
traditionally written with all capital letters.
Some examples: NASA, GERD, NORMAL, DOS, etc...
PERL is an acronym for Practical Extraction and Report Language, and
thus it stands to reason that one would write it "correctly" with all
capitals; that is the convention.
So, I don't understand why so many of you (it seems), keep picking
apart others posts with seemingly ignorant responses ... or am I the
ignorant one? Did Larry Wall unanimously declare that, against what
is proper, everyone should spell 'PERL' with all lowercase, save the
first letter? I never heard of such a thing.
Not every post responder does this, so this not necessarily directed
at those who don't. Neither is this a flame. This post is a genuine
attempt to find the answer to the question I stated above.
If I am unaware, please enlighten me. Then, if this seems like a
stupid question , I will not have to make a fool of myself by asking
it again.
Productive replys are appreciated!
Have a good day.
------------------------------
Date: Mon, 02 Jul 2001 05:10:12 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Query: PERL v.s. Perl ==> What's the difference???
Message-Id: <3B40027F.436310EC@acm.org>
codeslayer wrote:
>
> To Whoever Knows the Answer:
>
> I do not understand why so many of these posts where someone says
> "PERL", end up with some snyd comment to the effect of "its 'Perl' not
> 'PERL'". Firstly, that logic doesn't make sense. Acronyms are
> traditionally written with all capital letters.
>
> Some examples: NASA, GERD, NORMAL, DOS, etc...
>
> PERL is an acronym for Practical Extraction and Report Language, and
> thus it stands to reason that one would write it "correctly" with all
> capitals; that is the convention.
>
> So, I don't understand why so many of you (it seems), keep picking
> apart others posts with seemingly ignorant responses ... or am I the
> ignorant one? Did Larry Wall unanimously declare that, against what
> is proper, everyone should spell 'PERL' with all lowercase, save the
> first letter? I never heard of such a thing.
>
> Not every post responder does this, so this not necessarily directed
> at those who don't. Neither is this a flame. This post is a genuine
> attempt to find the answer to the question I stated above.
>
> If I am unaware, please enlighten me. Then, if this seems like a
> stupid question , I will not have to make a fool of myself by asking
> it again.
http://language.perl.com/newdocs/pod/perlfaq1.html#What_s_the_difference_between_p
http://bits.netizen.com.au/training/perlintro/x186.html
John
--
use Perl;
program
fulfillment
------------------------------
Date: Mon, 02 Jul 2001 09:55:05 +0200
From: Philip Newton <pne-news-20010702@newton.digitalspace.net>
Subject: Re: Query: PERL v.s. Perl ==> What's the difference???
Message-Id: <c890kt4u1uq3sverdghf49q6ujts4gba0a@4ax.com>
On 1 Jul 2001 21:48:44 -0700, weedmonster_99@yahoo.com (codeslayer)
wrote:
> Acronyms are traditionally written with all capital letters.
>
> Some examples: NASA, GERD, NORMAL, DOS, etc...
>
> PERL is an acronym for Practical Extraction and Report Language
No, it's not. The expansion was coined after the name was chosen and is
not the origin of the name 'Perl'.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Mon, 02 Jul 2001 06:16:41 GMT
From: "Joe C. Hecht" <joehecht@code4sale.com>
Subject: Re: Re:FAQ 9.15: How do I tell lies about decoding a CGI form?
Message-Id: <dlU%6.3908$I_1.836254@paloalto-snr1.gtei.net>
"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message news:3B3F3FEB.133FD97C@stomp.stomp.tokyo...
> > How do I decode a CGI form?
> (snipped blatant idiocy)
> This specific FAQ ranges from mule manure to idiocy to outright lies.
The truth has been spoken :)
I have been there and back, and all I have to say to the naysaying experts
who want the holy grail delivered to them on a silver platter is the problems
are so easy to see, and the solutions so easy to solve, that it would be an
insult to post them... afterall, they are the experts... right???
Joe
--
John Kaster is cycling to cure cancer! Lets help him out! http://homepages.borland.com/jkaster/tnt/
Jimmy Page is having a charity artwork sale: Action For Brazil's Children Trust: http://www.abctrust.org.uk/
Whole Lotta Love computing to cure cancer! http://www.wholelottalove.org/
------------------------------
Date: Mon, 2 Jul 2001 09:03:11 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: read/write ksh env array in Perl?
Message-Id: <994064591.782790186349303.gnarinn@hotmail.com>
In article <3b3f72aa.2773067@news-server.socal.rr.com>,
Sergio Vidales <svidales@please.no.spam.usa.net> wrote:
>On Sun, 1 Jul 2001 06:41:00 +0000 (UTC), steven.smolinski@sympatico.ca
>(Steven Smolinski) wrote:
>>Sergio Vidales <svidales@please.no.spam.usa.net> wrote:
>>> A ksh script that I need to use is doing something like this:
>>>
>>> $ MYARRAY[0]=TEST1
>>> $ MYARRAY[1]=TEST2
>>> $ echo ${MYARRAY[0]}
>>> TEST1
>>> $ echo ${MYARRAY[1]}
>>> TEST2
>>>
>>> I need to write a Perl script that can read and write to this array.
>>> It must be kept as an env variable since other scripts will read it as
>>> well. I have tried using $ENV and assigning it to a Perl array with
>>> little success.
>>
>
I do not have/know ksh, but are you sure ksh uses ENV for these arrays,
and not some private space?
If so, you might get ideas from looking at ENV after ksh does
the assignements, to get clues for how to duplicate it
For example:
$ MYARRAY[0]=TEST1
$ MYARRAY[1]=TEST2
$ perl -le 'print "$_=$ENV{$_}" foreach (keys %ENV);'
gnari
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 V10 Issue 1229
***************************************