[23330] in Perl-Users-Digest
Perl-Users Digest, Issue: 5550 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 23 18:05:43 2003
Date: Tue, 23 Sep 2003 15: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)
Perl-Users Digest Tue, 23 Sep 2003 Volume: 10 Number: 5550
Today's topics:
Re: () questions <mpapec@yahoo.com>
Re: () questions <mpapec@yahoo.com>
Re: () questions <mpapec@yahoo.com>
AUTOLOAD plus instance methods <daniel.rawson.take!this!out!@asml.nl>
Re: AUTOLOAD plus instance methods <skuo@mtwhitney.nsc.com>
Re: AUTOLOAD plus instance methods <jaspax@u.washington.edu>
Re: CGI.pm <Juha.Laiho@iki.fi>
class methods <mpapec@yahoo.com>
Re: for; while loop interations (laura fairhead)
How do I pass a value to a PERL script from an <a href? <NoSpamPlease@bellsouth.net>
Re: How do I pass a value to a PERL script from an <a h <asu1@c-o-r-n-e-l-l.edu>
Re: how to find the biggest ???? <syscjm@gwu.edu>
Re: How to return an HTML page from a Perl script ? <NoSpamPlease@bellsouth.net>
Re: How to return an HTML page from a Perl script ? <NoSpamPlease@bellsouth.net>
Re: How to return an HTML page from a Perl script ? (C. Olive)
Re: list-parsing problem <bart.lateur@pandora.be>
Perl web server question (Andrew Burton)
Re: Perl web server question (Malcolm Dew-Jones)
Re: Perl: how to stop users from executing commands fro (C. Olive)
persistant environment data (sburg)
Re: persistant environment data <minceme@start.no>
Re: persistant environment data <syscjm@gwu.edu>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 23 Sep 2003 22:33:14 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: () questions
Message-Id: <83b1nvc2iiprb7c4fg86k54lqee11emg2o@4ax.com>
X-Ftn-To: Eric J. Roode
"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote:
>> "Passing a map" is what happens to $_ when it gets transformed by map
>> (from right to left).
>>
>>>statement prints "2,4,6,8,10,12,14,16,18,20", which makes perfect
>>>sense to me. What is puzzling you about it?
>>
>> Well, map is a function which transforms list of values, so one could
>> expect[1] at least one value on the left side of map, for each element
>> coming from right. In case of empty list, () nothing gets through..?
>
>Right. Try this:
>
> @a = (1, 2, 3, (), 5, 6, (), 7);
>
>The ()s disappear, because the list on the right-hand side is
>"flattened" as it is evaluated. Were you perhaps expecting them to be
>undef? undef is a scalar value. Or perhaps an empty anonymous array
>ref, like []? That too is a scalar value.
Right, I'm expecting something (I know it can't be scalar), but I'm for sure
expecting something! :D
Tnx for explanation.
--
Matija
------------------------------
Date: Tue, 23 Sep 2003 22:38:55 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: () questions
Message-Id: <qkb1nvco5vpa99f6r7tl18b5bpk57mt9k4@4ax.com>
X-Ftn-To: Steve Grazzini
Steve Grazzini <grazz@pobox.com> wrote:
>That's right. The block (or expression) yields a *list* of values
>for each element in the input list. A common idiom for creating
>hashes transforms each input element into a key/value pair:
>
> my %hash = map { $_ => 1 } @input;
>
>Returning one element is probably more common, but returning an empty
>list makes sense too. It has the effect of "filtering"... in your case,
>though, grep() would work just as well, since you're not actually
>transforming the elements you keep.
Right now I'm tempted to start coding using only map since grep is obviously
redundant in Perl. ;)
--
Matija
------------------------------
Date: Tue, 23 Sep 2003 22:53:48 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: () questions
Message-Id: <6tb1nv8rnoec1e241nu2v4gdk1e60cj60g@4ax.com>
X-Ftn-To: Anno Siegel
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>> expect[1] at least one value on the left side of map, for each element
>> coming from right. In case of empty list, () nothing gets through..?
>
>The idea that list elements "pass map" in some sense to build the result
>list is not a useful visualization of the process.
>
>The map operator evaluates the block (or expression) in list context, once
>for each list element, and flattens the resulting lists into one big one.
>If the block returns an empty list on some occasions, the result list doesn't
>grow on that step.
>
>"map" also sets $_ to each list element in turn, and the block can make
>use of that, but that's no requirement. It can entirely ignore the original
>list elements. Seen like that, they certainly don't "pass through map".
Hm true; I usually use that sort of visualization to catch on longer
expressions.
--
Matija
------------------------------
Date: Tue, 23 Sep 2003 12:54:18 -0400
From: Dan Rawson <daniel.rawson.take!this!out!@asml.nl>
Subject: AUTOLOAD plus instance methods
Message-Id: <bkpts4$4h1ai$1@ID-122008.news.uni-berlin.de>
I have a tiny class (copied almost verbatim from the perltoot pages) which has some AUTOLOAD methods plus one other.
When I run the attached, it dies with "Can't access DESTROY field . . . ." at the very end. What am I doing wrong??
TIA . . . .
Dan
#!/usr/bin/env perl -w
package myTest;
use Carp;
our $AUTOLOAD;
use strict;
my %config = (
recursive => 0, # Bool
overwrite => 0, # Bool
);
sub new()
{
my $class = shift;
my $self = {
_permitted => \%config,
%config,
};
bless $self, $class;
return $self;
}
sub AUTOLOAD()
{
my $self = shift;
my $type = ref($self) || die;
my $name = $AUTOLOAD;
$name =~ s/.*://;
unless (exists $self->{_permitted}->{$name})
{
croak "Can't access $name field in object of class $type";
};
if (@_)
{
return $self->{$name} = shift;
}
else
{
return $self->{$name}
}
}
sub show_config()
{
my $self = shift;
print "Recursive: ".($self->recursive() ? "True" : "False")."\n";
print "Over-write: ".($self->overwrite() ? "True" : "False")."\n";
}
1;
package MAIN;
my $fred = myTest->new();
my $mary = myTest->new();
$mary->recursive(1);
$mary->show_config();
------------------------------
Date: Tue, 23 Sep 2003 13:04:20 -0700
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: AUTOLOAD plus instance methods
Message-Id: <Pine.GSO.4.21.0309231255010.24610-100000@mtwhitney.nsc.com>
On Tue, 23 Sep 2003, Dan Rawson wrote:
> I have a tiny class (copied almost verbatim from the perltoot
> pages) which has some AUTOLOAD methods plus one other. When I run
> the attached, it dies with "Can't access DESTROY field . . . ." at
> the very end. What am I doing wrong??
>
> TIA . . . .
>
> Dan
perltoot does describe DESTORY as the destructor used by perl. Your
AUTOLOAD subroutine is intercepting this call. You can either
define a DESTROY subroutine in your package (see below):
>
> #!/usr/bin/env perl -w
> package myTest;
> use Carp;
>
> our $AUTOLOAD;
> use strict;
> my %config = (
> recursive => 0, # Bool
> overwrite => 0, # Bool
> );
>
> sub new()
> {
> my $class = shift;
> my $self = {
> _permitted => \%config,
> %config,
> };
> bless $self, $class;
> return $self;
> }
sub DESTORY { } # do nothing
> sub AUTOLOAD()
> {
> my $self = shift;
> my $type = ref($self) || die;
> my $name = $AUTOLOAD;
> $name =~ s/.*://;
# or handle DESTORY within AUTOLOAD:
return if $name eq 'DESTROY';
> unless (exists $self->{_permitted}->{$name})
> {
> croak "Can't access $name field in object of class $type";
> };
> if (@_)
> {
> return $self->{$name} = shift;
> }
> else
> {
> return $self->{$name}
> }
>
> }
(remainder snipped)
--
Hope this helps,
Steven
------------------------------
Date: Tue, 23 Sep 2003 13:02:21 -0700
From: JS Bangs <jaspax@u.washington.edu>
Subject: Re: AUTOLOAD plus instance methods
Message-Id: <Pine.A41.4.58.0309231258150.88178@dante42.u.washington.edu>
Dan Rawson sikyal:
> I have a tiny class (copied almost verbatim from the perltoot pages)
> which has some AUTOLOAD methods plus one other. When I run the attached,
> it dies with "Can't access DESTROY field . . . ." at the very end.
> What am I doing wrong??
This is a common problem--I've run into it myself.
Perl calls a method named DESTROY() on all objects when they're garbage
collected, with special magic to ensure that if this method doesn't exist
no errors are generated. However, before that happens the DESTROY gets
caught in the AUTOLOAD method, and so generates this message.
There's two ways to fix this:
> sub AUTOLOAD()
> {
> my $self = shift;
> my $type = ref($self) || die;
> my $name = $AUTOLOAD;
> $name =~ s/.*://;
Here you could add something like:
return if $name eq 'DESTROY';
> unless (exists $self->{_permitted}->{$name})
> {
> croak "Can't access $name field in object of class $type";
> };
> if (@_)
> {
> return $self->{$name} = shift;
> }
> else
> {
> return $self->{$name}
> }
>
> }
Or you could add
sub DESTROY {}
This means that DESTROY does exist (but does nothing), so it never enters
the AUTOLOAD routine.
--
Jesse S. Bangs jaspax@u.washington.edu
http://students.washington.edu/jaspax/
http://students.washington.edu/jaspax/blog
Jesus asked them, "Who do you say that I am?"
And they answered, "You are the eschatological manifestation of the ground
of our being, the kerygma in which we find the ultimate meaning of our
interpersonal relationship."
And Jesus said, "What?"
------------------------------
Date: Tue, 23 Sep 2003 15:32:01 GMT
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: CGI.pm
Message-Id: <bkpot4$ki2$1@ichaos.ichaos-int>
"Trent Curry" <tcurrey@no.no.no.i.said.no> said:
>On that note, I've seen the docs at www.php.net, and I'd say they too would
>require getting aquainted too for any successful task in php, save maybe
>Hello World level examples...
They do require -- worst thing being that the single set of
documentation tries to cover several versions, and so contains
examples (and even syntax/usage descriptions) that either require
older or newer version of PHP that you happen to be using. And
of course, different parts of the documentation are primarily
written for different PHP versions.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ 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: Tue, 23 Sep 2003 22:53:50 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: class methods
Message-Id: <s3c1nvo4cmr4e6gfoac20d7tumuijqctkj@4ax.com>
I have situation where /class method/ can be called inside and outside of
package so I have to know when to throw away the first argument. I found
that
shift if $_[0] eq __PACKAGE__;
should work, but is there a better way to distinguish inside and outside
calls?
--
Matija
------------------------------
Date: Tue, 23 Sep 2003 18:29:29 GMT
From: run_signature_script_for_my_email@INVALID.com (laura fairhead)
Subject: Re: for; while loop interations
Message-Id: <3f709052.72605143@NEWS.CIS.DFN.DE>
On Mon, 22 Sep 2003 21:00:33 -0700, Jayaprakash Rudraraju <prakashREMOVE@CAPITALSece.arizona.edu> wrote:
>
>Hi,
>
>The following two snippets of code are iterating the while loop same
>number of times. I am not able to comprehend the reason. Thanks in advance
>for your explanations.
>
>$intv = 1.1;
>while ($intv > 0.4) {
> print "$intv\n";
> $intv -= 0.1
>}
>
>$intv = 1.1;
>while ($intv >= 0.4) {
> print "$intv\n";
> $intv -= 0.1
>}
Hi,
I think you'll see what is going on easily if you try to
work out what 1/10 is in binary.
Floating point is not a precise way of dealing with values.
Whatever the number of bits used to store the FP values it
is a fixed number and so you are mapping infinite set of rational
numbers (a/b ) into a finite space and the result is that there
are "holes" (some, actually infinitely many, rationals get lost).
This ends up giving you a type of arithmetic that has some very
strange properties; rather like the moire patterns that appear
if you draw a lot of lines on a computer screen because those
lines aren't really straight they're a sequence of dots approximating
where the line would be if you could draw it. That's what you're
witnessing here, if you want 100% accuracy you have to use integer
methods eg;
(no code tested)
(i) integer scaling
~~~~~~~~~~~~~~~~~~~
$intv = 11;
while ($intv > 4) {
print $intv/10."\n"; # print approximation of intv/10
# for exact display use string splicing
$intv -= 1;
}
$intv = 11;
while ($intv >= 4) {
print $intv/10."\n"; # print approximation of intv/10
# for exact display use string splicing
$intv -= 1;
}
(ii) integer/modulus(=fixed=10)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$intv = 1; $modv= 1;
while ($intv*10+$modv > 4) {
print $intv.".".$modv."\n";
if( ($modv -= 1) < 0)
{
$intv -= 1; $modv += 10;
}
}
}
$intv = 1; $modv = 1;
while ($intv*10+$modv >= 4) {
print $intv.".".$modv."\n";
if( $modv -= 1 < 0)
{
$intv -= 1; $modv += 10;
}
}
}
(i) & (ii) should do for most uses where you only need a fixed
precision, really you are just translating everything directly
into integers,
(iii) integer/modulus(=variable=MODU)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Just change 10 in the above for $MODU
You can even keep a seperate MODU value for each value you use
and write some functions to perform operations on these type
of values (intv,modv,MODU) == intv+modv/MODU
So this will in theory be able to deal with rational numbers
in the way we would expect them to behave.
Of course the problem is that MODU can and will grow arbitarily
large and really you need some "clean-up" function to reduce
modv/MODU (finding any common factor and dividing) just to make
sure it doesn't become unneccesarily large at a given time.
You won't be able to calculate square roots and sines, cosines, etc
in most cases because it is not possible to do that (they don't
produce rational numbers in a lot of cases so you aren't actually
calculating them when you do $a=sqrt($b); it is an approximation
of course the problem with FP is that it doesn't exactly come
screaming in your face that $a=$b/$c migth be an approximation or
that $a=$b+$c can introduce errors!)
The time to calculate an operation will increase with the complexity
of the number until eventually it takes ages and megabytes of workspace
and of course at some point the system won't have the resources to
deal with it anymore ( before that you have to write a function
or get a perl module to deal with arbitarily large integers)
Usually when people utilise floating point it is because the
loss in accuracy doesn't matter (because it is a leisure application
maybe). A thing to be wary of is belief that using some very
high precision FP will somehow increase the overall accuracy of
the math - each time you perform an operation on a value in FP
you are on average introducting more error into it, and this error
will rapidly get larger the more operations you perform, as it
propagates. If you are doing some repeated operation you can say byebye
to any hint of mathematical accuracy over time and the FP size won't
have much effect on this. If it is an application where the accuracy is of
any importance (aside from cosmetic) then either (i) calculate possible
error bounds (I don't know if there are studies on this but it seems
very difficult because you have to factor in every single operation
and often won't even know the size of the FP given that your program
may run in different environments) (ii) use integer methods
Just the other day I was using something called 'mogrify' to produce some
thumbnails for a new website gallery and I noticed that the scaling method
it uses is obviously the incorrect FP method because every other picture
was losing 1 pixel on a length and/or width; you don't get that if you
use integer methods but of course it's a bit more work to code it.
>
>Prakash
>--
>94.5% of all statistics are made up.
very funny :)
seeyafrom
l
--
echo alru_aafriehdab@ittnreen.tocm |sed 's/\(.\)\(.\)/\2\1/g'
------------------------------
Date: Tue, 23 Sep 2003 15:09:00 -0400
From: "Rodney" <NoSpamPlease@bellsouth.net>
Subject: How do I pass a value to a PERL script from an <a href?
Message-Id: <HQ0cb.20401$an.10076@bignews6.bellsouth.net>
I want to use a regular HTML href to call a PERL script and I also want to
include information to pass to the PERL script.
IE:
<a href="/cgi-local/PerlScript.pl">
I would like to pass a value such as 567 along with this call.
Can it be done using a regular <A HREF= > ?
If so, what is the syntax?
--
...
`·.¸¸.·´¯`·.¸¸.·´¯`·-> rodney
------------------------------
Date: 23 Sep 2003 19:37:53 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: How do I pass a value to a PERL script from an <a href?
Message-Id: <Xns93FF9F0376E87asu1cornelledu@132.236.56.8>
"Rodney" <NoSpamPlease@bellsouth.net> wrote in
news:HQ0cb.20401$an.10076@bignews6.bellsouth.net:
> I want to use a regular HTML href to call a PERL script and I also
> want to include information to pass to the PERL script.
>
> IE:
> <a href="/cgi-local/PerlScript.pl">
>
> I would like to pass a value such as 567 along with this call.
>
> Can it be done using a regular <A HREF= > ?
> If so, what is the syntax?
Rodney,
At this point, you would do yourself and everyone else a favor by taking a
deep breath and reading the posting guidelines for this newsgroup. They are
regularly posted here (also available on the WWW at
http://mail.augustmail.com/~tadmc/clpmisc.shtml).
CGI specific questions are is off-topic here. You might want to ask CGI-
specific questions, you may want to go to
comp.infosystems.www.authoring.cgi.
As for this specific questions, find out information about GET requests.
Sinan.
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: Tue, 23 Sep 2003 11:09:19 -0400
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: how to find the biggest ????
Message-Id: <3F70621F.5060508@gwu.edu>
mkl wrote:
> If I have a file ,named txt
>
> ###############
> a (298:298) (9:9)
> b (2:2)
> c (3:3)
> d (5:5)
> ############################
>
>
> how do i select the biggest one and print ?
>
>
Biggest what? And how are you determining
that x is bigger than y?
Chris Mattern
------------------------------
Date: Tue, 23 Sep 2003 13:20:45 -0400
From: "Rodney" <NoSpamPlease@bellsouth.net>
Subject: Re: How to return an HTML page from a Perl script ?
Message-Id: <cf%bb.20353$an.6726@bignews6.bellsouth.net>
I found a simple way to do it.
No CGI libraries or anything is required.
NOTE: It's important to include the \n\n and the return value of 1
===============================
$theUrl = http://www.yourplace.com
sub Redirect_page {
print "Location: ", $theUrl,"\n\n";
1;
}
===============================
--
...
`·.¸¸.·´¯`·.¸¸.·´¯`·-> rodney
------------------------------
Date: Tue, 23 Sep 2003 13:27:54 -0400
From: "Rodney" <NoSpamPlease@bellsouth.net>
Subject: Re: How to return an HTML page from a Perl script ?
Message-Id: <Vl%bb.20357$an.309@bignews6.bellsouth.net>
NOTE:
In my previous post, I defined the URL link and the Newsgroup caused it to
be a URL-Link.... So, you're not seeing the double quots around it. You
must include double quotes around the URL address... ie; "your URL here"
--
...
`·.¸¸.·´¯`·.¸¸.·´¯`·-> rodney
------------------------------
Date: 23 Sep 2003 12:24:47 -0700
From: newsbot@sbcglobal.net (C. Olive)
Subject: Re: How to return an HTML page from a Perl script ?
Message-Id: <a813a9a.0309231124.558548cb@posting.google.com>
"Rodney" <NoSpamPlease@bellsouth.net> wrote in message news:<ZpYbb.20243$an.644@bignews6.bellsouth.net>...
> 1. I want to have a ahref link, on an HTML page, point to a PERL script.
> 2. The Perl script will open an existing HTML document and change some of
> its content.
> 3. After altering the HTML document, I want it to be returned to the Web
> Client.
>
>
> I don't want to re-write the entire HTML document with in the PL script
> (because then the HTML document can not be easily edited using an HTML
> editor). I only want to change certain content then return the document to
> the client.
>
> How do I do that?
>
> The PERL script changes the document.... but then it doesn't "return" it ??
>
I see you've already received the answer I would have offered:
HTML::Template. Highly recommended. If you need a sample interaction
to help you put the pieces together, just say so and I'll drop one
here for you to look at. Examples always help... 8-) HTML::Template
rocks...
Chris
-----
Chris Olive
chris [I'm at] technologEase [dot] com
http://www.technologEase.com
(pronounced "technologies")
------------------------------
Date: Tue, 23 Sep 2003 15:28:33 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: list-parsing problem
Message-Id: <c1p0nv8msmp2smg05nf3hljv9flrhh9adb@4ax.com>
Marcus Claesson wrote:
>I have a silly little list-parsing problem that I can't get my head
>around, and I'm sure some of you have come across it before.
>
>I have a list like this:
>
>1 a
>2 b
>2 c
>3 a
>4 d
>4 d
>4 e
>4 f
>5 g
>
>and I want to make the first column non-redundant and collect the
>second column values on the same line, like this:
>
>1 a
>2 b,c
>3 a
>4 d,e,f
>5 g
>
>Please note that line 4 only has one 'd'.
IMO your problem isn't in the parsing, but it the data storing. For the
second, i'd use a hash of which only the keys are relevant, and the
order if you want the original order. For the first column, I'm not
sure. Can you use an array? A hash that is sorted on the numeric value
of the string, or simply the original order?
Assuming an array will work, let's try this:
# Fill the data structure
my @data;
while(<DATA>) {
chomp;
my($i, $val) = split " ", $_;
for($data[$i]) {
$_->{$val} ||= keys %$_;
}
}
# Let's check what we've got
use Data::Dumper;
print Dumper \@data;
# Generate the report
local ($\, $,) = ("\n", "\t");
my $i = 0;
foreach (@data) {
defined or next;
print $i, join ",", sort { $_->{$a} <=> $_->{$b} } keys %$_;
} continue {
$i++;
}
__DATA__
(your data follows)
--
Bart.
------------------------------
Date: 23 Sep 2003 20:18:51 GMT
From: tuglyraisin@aol.commcast (Andrew Burton)
Subject: Perl web server question
Message-Id: <20030923161851.10417.00000078@mb-m06.aol.com>
This may be an HTTP question, but I'm hoping since I'm using Perl and Perl
modules to write this little server, it'll be considered a Perl question. The
program below works. It will run, listen to a port, and serve messages back
according to the method. However, I can't seem to find the data when I send it
via the POST method. Can someone point me to a website that explains how to
parse POST data with Perl. A site, that is, that doesn't use HTTP::Daemon.
;-) I may have to eventually resort to that, but I'd love to get this working
without it. Thanks!
[code]
#!/usr/bin/perl -w
# bserver.pl
# by: Andrew Burton - tuglyraisin@aol.com
#####
# modules
use strict;
use IO::Socket;
use Net::hostent;
# variables
my $HOME = 'c:\tardis';
my $PORT = 9999;
my $HOST = 'buta.hammerofgod.net';
my $client = '';
my $server = IO::Socket::INET->new( LocalAddr => $HOST,
LocalPort => $PORT,
Proto => 'tcp',
Listen => SOMAXCONN,
ReuseAddr => 1, ) or die "$!\n";
# makes sure it's working
if ($server) { print "Server for $HOST running on $PORT\n"; }
while ($client = $server->accept()) {
# $client->autoflush(1);
my $request = $client->getline();
$request =~ s/\r//g;
chomp ($request);
print $request . "\n";
if ($request =~ m/^GET/) {
print $client "HTTP/1.0 200 OK\n",
"Content-Type: text/html\n\n";
print $client "GET: Yes.\n";
}
elsif ($request =~ m/^POST/) {
print $client "HTTP/1.0 200 OK\n",
"Content-Type: text/html\n\n";
print $client "Post: Yes.\n";
}
close $client;
}
[/code]
Andrew Burton - tuglyraisin at aol dot com
Felecia Station on Harvestgain - http://www.darkbeast.com/
"I often question my sanity; it has yet to give me a straight answer."
"And if you're bored, it's because... you're boring." - Matt Drudge
------------------------------
Date: 23 Sep 2003 14:15:56 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Perl web server question
Message-Id: <3f70b80c@news.victoria.tc.ca>
Andrew Burton (tuglyraisin@aol.commcast) wrote:
: This may be an HTTP question, but I'm hoping since I'm using Perl and Perl
: modules to write this little server, it'll be considered a Perl question. The
: program below works. It will run, listen to a port, and serve messages back
: according to the method. However, I can't seem to find the data when I send it
: via the POST method. Can someone point me to a website that explains how to
: parse POST data with Perl. A site, that is, that doesn't use HTTP::Daemon.
: ;-) I may have to eventually resort to that, but I'd love to get this working
: without it. Thanks!
: [code]
: #!/usr/bin/perl -w
: # bserver.pl
: # by: Andrew Burton - tuglyraisin@aol.com
: #####
: # modules
: use strict;
: use IO::Socket;
: use Net::hostent;
: # variables
: my $HOME = 'c:\tardis';
: my $PORT = 9999;
: my $HOST = 'buta.hammerofgod.net';
: my $client = '';
: my $server = IO::Socket::INET->new( LocalAddr => $HOST,
: LocalPort => $PORT,
: Proto => 'tcp',
: Listen => SOMAXCONN,
: ReuseAddr => 1, ) or die "$!\n";
: # makes sure it's working
: if ($server) { print "Server for $HOST running on $PORT\n"; }
: while ($client = $server->accept()) {
: # $client->autoflush(1);
: my $request = $client->getline();
: $request =~ s/\r//g;
: chomp ($request);
: print $request . "\n";
You haven't finished reading the header yet. You need to read all the
lines up to the empty line that indicates the end of the header. You will
want to parse them to find what they tell you. You will find it
interesting and useful to print them out.
: if ($request =~ m/^GET/) {
: print $client "HTTP/1.0 200 OK\n",
: "Content-Type: text/html\n\n";
: print $client "GET: Yes.\n";
: }
: elsif ($request =~ m/^POST/) {
: print $client "HTTP/1.0 200 OK\n",
: "Content-Type: text/html\n\n";
: print $client "Post: Yes.\n";
In here you would have to continue to read the socket to get the rest of
the data. The headers you read earlier will include one (probably
content-length) that indicates the number of bytes of data that need to
be read.
------------------------------
Date: 23 Sep 2003 12:20:05 -0700
From: newsbot@sbcglobal.net (C. Olive)
Subject: Re: Perl: how to stop users from executing commands from browser
Message-Id: <a813a9a.0309231120.2235ce96@posting.google.com>
qasim@ti.com (Nick) wrote in message news:<9d603421.0309221508.5ba5c9fb@posting.google.com>...
> I'm working on an HTML file that calls cope of Perl scripts with
> parameters.
> If you take your cursor over to the link, you can see the command that
> will be send to the perl script and at this point user can modify that
> and execute it from web browser. How can i prevent this from
> happening?????
> Anyway to block users from executing any commands from web browser????
>
> Thanks in advance.
> Nick
Aside from all the necessary warnings and help concerning ideas to
keep arbitrary user commands from being sent to and executed on your
web server, I *think* what you are saying is you don't want ANYTHING
that you have for your HREFs to show up on the client's browser in
their status window. For instance, if you have this in your HTML:
<a href="/cgi-bin/foo.pl?idx=3&config=foobar">Click me</a>
When you run your mouse over the link, you see this in the status
window of the browser on the client side:
[http://www.somewhere.com/cgi-bin/foo.pl?idx=3&config=foobar]
And you don't want them to see that... That's what you mean right?
Understand first, there is no way you can block a truly technically
astute person from *finding* this information. There are a number of
stratigies you can use to block this from the average user and/or make
it difficult to find. Before mentioning some however, understand
this: The effort you make here is somewhat and largely in vain because
a non-technical user doesn't know enough about what they are seeing to
do something damaging with it ANYWAY, and for the person that DOES
know what to do with that kind of information, they also have the
ability, in most cases, to *find* it even if you take pains to hide
it. So that's the delimma in this situation.
I like to "hide" this kind of information for two reasons: (1) I think
seeing a real message in the status window instead of some URL
information adds to the polish of the site, and (2) simply because
seeing a real message at least doesn't plant any ideas in someone's
head (that DOES know what they are doing) in the first place that
could happen if the URL/script information showed up in the status
window (eg. "Hey, did you see THAT??!! I wonder what would happen if
I did THIS...!") So a minimal effort has some reward; a huge effort
is not worth the time.
Strategy #1: Use onMouseOver events for your anchor tags:
<a href="/foo.pl?idx=3&config=foobar" onMouseOver="parent.status='Show
Membership Details'; return true;" onMouseOut="parent.status='';
return true;">Show Membershp Details</a>
When the mouse hovers the link, then instead of the actual URL script
showing up, all they see is the very friendly message "Show Membership
Details" in their browser status window.
Cons: Relies on JavaScript support on the client-side browser being
turned on; User can still see the script call using "View Source" in
the browser.
Strategy #2: To block URL from reforming in the address window:
Use frames. A variation on this is to use a hidden frame of size 0.
A further variation is to place client-side JS wrappers to server side
calls inside the hidden frame and have client-side wrappers make the
real server-side calls. So even an inspection with "View Source" in
the non-hidden frame shows only client-side calls, not server calls.
Combine with strategy #1 and this is pretty good although I don't make
this large of an effort myself. I use hidden frames (almost always)
and onMouseOvers; anything beyond and it seems like a waste of time
because...
Like I said, you are only delaying the inevitable from the truly
technical user. There is no way to completely hide your call. I
believe strategy #1 is worth doing because it takes minimal effort and
at least disallows ideas from initially forming in the minds of those
that know what they are doing. For the person that doesn't know a
cgi-bin URL from an internet email address, it doesn't matter anyway
other than for the polish of your site.
Beyond this, any other precautions are simply security precautions and
don't answer your question directly. You've been offered a few of
these solutions. There are a few more -- some of them again with
minimal effort that are worth the time to implement -- but none that
block the information from being seen on the client side as you asked.
In brief, onMouseOver events are your best bet.
chris
-----
Chris Olive
chris [I'm at] technologEase [dot] com
http://www.technologEase.com
(pronounced "technologies")
------------------------------
Date: 23 Sep 2003 11:42:12 -0700
From: sburg@avaya.com (sburg)
Subject: persistant environment data
Message-Id: <2cb2a222.0309231042.61b6e0c8@posting.google.com>
I am trying to convert the following line from a makefile into perl:
. shell_script_to_get_env_data && java Main
When run on a Unix command line the
. shell_script_to_get_env_data
sets some env variables.
Then some objects instantiated from Main.java need to use
those env variables.
The following perl lines don't work:
system(". shell_script_to_get_env_data");
system("java Main");
Main fails because its shell doesn't have the env variables set.
How do I put these commands together in Perl so that the environment
variables set up by the shell script are accessable by the Java
program?
Thanks,
Shawna
------------------------------
Date: Tue, 23 Sep 2003 18:46:16 +0000 (UTC)
From: Vlad Tepes <minceme@start.no>
Subject: Re: persistant environment data
Message-Id: <bkq4do$5kp$1@troll.powertech.no>
sburg <sburg@avaya.com> wrote:
> I am trying to convert the following line from a makefile into perl:
> . shell_script_to_get_env_data && java Main
>
> When run on a Unix command line the
> . shell_script_to_get_env_data
> sets some env variables.
>
> Then some objects instantiated from Main.java need to use
> those env variables.
>
> The following perl lines don't work:
> system(". shell_script_to_get_env_data");
> system("java Main");
> Main fails because its shell doesn't have the env variables set.
>
> How do I put these commands together in Perl so that the environment
> variables set up by the shell script are accessable by the Java
> program?
How about
system("./shell_script_to_get_env_data && java Main");
Or you could set the environment in perl, then run java:
$ENV{myvar} = "somevalue";
system("java Main");
--
Vlad
------------------------------
Date: Tue, 23 Sep 2003 15:30:00 -0400
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: persistant environment data
Message-Id: <3F709F38.5060901@gwu.edu>
sburg wrote:
> I am trying to convert the following line from a makefile into perl:
> . shell_script_to_get_env_data && java Main
>
> When run on a Unix command line the
> . shell_script_to_get_env_data
> sets some env variables.
>
> Then some objects instantiated from Main.java need to use
> those env variables.
>
> The following perl lines don't work:
> system(". shell_script_to_get_env_data");
> system("java Main");
> Main fails because its shell doesn't have the env variables set.
>
> How do I put these commands together in Perl so that the environment
> variables set up by the shell script are accessable by the Java
> program?
>
Have you tried
system(". shell_script_to_get_env_data && java Main");
?
Chris Mattern
------------------------------
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 5550
***************************************