[19632] in Perl-Users-Digest
Perl-Users Digest, Issue: 1827 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 27 00:10:30 2001
Date: Wed, 26 Sep 2001 21:10: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: <1001563809-v10-i1827@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 26 Sep 2001 Volume: 10 Number: 1827
Today's topics:
Problem using Modules (RoJo)
Re: Problem using Modules <bart.lateur@skynet.be>
Re: Security of letting user specify regex in CGI scrip (Jay McGavren)
Re: String Comparison Problem (Martien Verbruggen)
validating handle to perl module (Rob)
wait interferes with $? from system call <tom.hoffmann@worldnet.att.net>
Re: Werte aus einem Array =?iso-8859-1?Q?l=F6schen?= (Martien Verbruggen)
Win32 Perl - Setting ENV Variables from Command-line <removespamjeremyalansmith@netscapeonline.co.uk>
Re: Win32 Perl - Setting ENV Variables from Command-lin <wyzelli@yahoo.com>
Re: XML::Writer question... how to write output to file <jxm96c@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 26 Sep 2001 22:44:01 GMT
From: rojo@mindspring.com (RoJo)
Subject: Problem using Modules
Message-Id: <3bb25505.83184222@news.mindspring.com>
I'm trying to learn how to use Packages. I have a web page (.htm)
with a form that invokes a script (.pl), which "uses" a couple of
modules (.pm).
The DzSoft editor tells me that the syntax in the .pl & the .pm files
is fine. Excerpts are included below.
When I run this from my web site, IE gives me the message "The page
cannot be displayed". Since I've already tested these methods in a
standalone Perl script, I'm led to believe I did something wrong with
the packages. So I tried to run it from my hard drive (where I have
ActivePerl installed). I get the "Save As" dialog box, which asks me
if I want to save the .pl file. This makes me think my (Win2000
Professional) file associations are wrong, so I associated .pl and .pm
with perl.exe, but to no avail. Still got "Save As".
Help! I don't know what I'm doing wrong, and I don't know how to
determine what the problem is. I think I have two separate problems,
local vs. web-based environments. P.S. I just bought a book,
"Programming Perl". So there's hope for me.
Ron (rojo@mindspring.com)
Code from file_maint_using_modules.pl:
#!/usr/local/bin/perl -w
use enterprise_methods;
use xml_methods;
open_file("XMLFILE","../data/rjassets.xml");
Code from enterprise_methods.pm:
# enterprise_methods.pm - methods available to any RJ Application
package enterprise_methods;
BEGIN {
use Exporter();
our(@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $glbl_id);
@ISA = 'Exporter';
@EXPORT = ('&open_file', '&close_file', '&backup_file',
'&display_error');
@EXPORT_OK = ('glbl_id', '$retval');
%EXPORT_TAGS = ();
}
$glbl_id = 0;
return 1;
# Subroutine open_file opens a file on the server.
sub open_file {
print "Content-type:text/html\n\n";
print "<html><head><title>file_maint.cgi</title></head><body><font
face='Arial' size='2'>";
open($_[0],$_[1]) or display_error("Open failure: $!");
$retval = flock(XMLFILE,LOCK_EX);
print "RC for flock = $retval";
$retval = '1';
return $retval;
}
------------------------------
Date: Wed, 26 Sep 2001 23:33:25 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Problem using Modules
Message-Id: <s2p4rt4gufdo1egt8hh99c97s2ct1mruma@4ax.com>
RoJo wrote:
>When I run this from my web site, IE gives me the message "The page
>cannot be displayed". Since I've already tested these methods in a
>standalone Perl script, I'm led to believe I did something wrong with
>the packages.
Not necessarily so. Does your script know where to find those modules?
If you don't have access to the server error log, try to convince the
script to send all error messages to your browser. The module CGI::Carp
could help. If you don't have that, do something very brutal: put this
at the top of your script:
BEGIN {
open STDERR, ">&STDOUT;
print "Content-Type: text/html\n\n";
print "<PRE>";
}
This is not a permanent change to your script! Only till you get it
working.
Ideally, all '&' and '<' in what you print should be escaped. If you
fail to understand what you see in the browser, try looking at the
"source".
The reasone why I use a content-type of text/html, is because MSIE acts
strangely when it encounters a content-type of text/plain. It might even
try to run the output of your script through perl.
--
Bart.
------------------------------
Date: 26 Sep 2001 20:34:15 -0700
From: sgarfunkle@hotmail.com (Jay McGavren)
Subject: Re: Security of letting user specify regex in CGI script?
Message-Id: <6bb557e1.0109261934.509e5a48@posting.google.com>
> No No NO! Cargo cult CGI-decoding crap deleted.
>
> use CGI qw(param);
> $input{'regex'} = param('regex');
Ah, much smoother. Guess I'll go with it. Thanks!
> It's safe this way, except that a denial-of-service attack is
> possible. But they won't be able to do anything that you wouldn't
> want them to do, if that's what you're worried about.
So the theorizing I'd heard about guessing the contents of variables
elsewhere in the script is off the mark? I admit I can't see how it'd
be done, personally.
> Jay> Better yet, anyone know
> Jay> of any modules that have done all the hard work for me? Ideally,
> Jay> instead of a Perl regex, the user could type in a search like
> Jay> '"continuous string" AND otherstuff NOT badstuff'...
> Yes... there are various modules to parse and execute searches like
> that. The CPAN is a wonderful thing... www.cpan.org
Well, I'd already done a module search for "search" and another for
"regex" on search.cpan.org, but closest thing those turned up were
modules intended for indexing and searching large numbers of files
(and nothing to form regexes from plain English that I could see). Am
I looking for the wrong kind of module?
For the time being, though, I guess I can just interpolate a Perl
regex from a form field. My users won't be able to figure out the
more powerful aspects, but if they type in 'a string' then ('try to
match a string' =~ /$user_regex/i) will match and I guess that's good
enough. Many thanks for the help!
------------------------------
Date: Thu, 27 Sep 2001 09:28:10 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: String Comparison Problem
Message-Id: <slrn9r4p4a.8ai.mgjv@martien.heliotrope.home>
On 26 Sep 2001 10:06:27 -0700,
Matt Uhrich <muhrich@deltadentalpa.org> wrote:
> Hi,
>
> Here is the program I am having problems with:
> #!d:/perl/bin/perl.exe
No -w, and no use strict.
Before posting here, you should always make sure your program uses both.
The main reason for this is that those two (especially -w) can help you
find many bugs. In fact, your program will elicit many warnings from
perl.
> $sourcedir = "d:\\data";
my $sourcedir = "d:/data";
> if ( $first == "-" ) {
You get a warning here of the form 'Argument "%s" isn't numeric in
numeric eq (==)', and the perldiag documentation explains what to do
about that.
> if ( $current_group != $previous_group ) {
And here you get one saying something like 'Argument "%s" isn't numeric
in numeric ne (!=)'.
Could you please promise to enable warnings and strictures on your code?
it'll make your life a lot easier, because you won't have to use Usenet
as a debugging tool anymore, or at least not as often.
Martien
--
Martien Verbruggen |
Interactive Media Division | I took an IQ test and the results
Commercial Dynamics Pty. Ltd. | were negative.
NSW, Australia |
------------------------------
Date: 26 Sep 2001 17:49:38 -0700
From: robsjobs@hotmail.com (Rob)
Subject: validating handle to perl module
Message-Id: <4ae33a7b.0109261649.19bc1ba2@posting.google.com>
I noticed an odd behavior with Net::FTP and am trying to address it.
I noticed that using the Net::FTP->new($host) would occasionally fail
without any good reason. So I wrote the following to address the
issue:
sub connect_to_host {
#{ code here for other stuff}
my $Ccount=0; #Connection count (attempts)
RENEW:
if ($Ccount < 5) {
$Ccount+=1;
$ftp=Net::FTP->new($host) or goto RENEW;
} else {
print STDERR "Cannot connect to $host\n";
exit 1;
}
if ( ! $ftp->login($login,$pass) ) {
print STDERR "Cannot login to $host\n";
exit 1;
}
#{ code here for other stuff}
}
I have never made it to ($Ccount == 5) when the host was up, so the
code addresses that issue...
I am transfering 500+ files in a day with the script running every 5
minutes and transfering whatever files are ready for distributing. I
realized that it is rediculous to:
while (! [out of files]) {
connect; -> put-next-file; -> disconnect; #repeat
}
So I changed my code to connect/login once and then put each of the
fifty or so files, then disconnect. Seems to work very well.
The reason for the post though, is this... When I do my put (in
another sub routine,) how can I validate that the global variable $ftp
is still valid? I would like to retry the connect without croaking
but cannot identify a surefire way to validate the handle. Would I be
best off asking for a pwd or dir from the $host or can Net::FTP
validate the handle?
Thanks for your thoughts... (the constructive ones that is ;-)
Robert
------------------------------
Date: Thu, 27 Sep 2001 01:13:57 GMT
From: Tom Hoffmann <tom.hoffmann@worldnet.att.net>
Subject: wait interferes with $? from system call
Message-Id: <p3vs7.11824$W8.994180@bgtnsc04-news.ops.worldnet.att.net>
I am running into a problem using the 'wait' function in a subroutine
that handles SIGCHLD signals. What I have found is that a '$waitpid =
wait' statement in the SIGCHLD handler subroutine sets the return code
($?) from the corresponding 'system' call that forked a process to '-1'
even though the system call was successful.
Since I can get a SIGCHLD signal from a 'system' call as well as from
the process I forked, I need the 'wait' function so I know whether it
was my forked process that ended or one of the 'system' calls.
I can get around this problem by ignoring the SIGCHLD signals from the
system calls (by setting a flag that is used by the SIGCHLD handler),
but this seems kind of clumsy and does not allow me to reap the child
processes. However, when I use this approach, the value of the return
code ($?) from the 'system' call is '0' as expected.
Here is the test code I am running that is causing me problems. The
'system' call always returns a '-1' so I am in an endless loop. How can
I preserve the value of $? from a 'system' call and still use the
'wait' function in a subroutine that handles SIGCHLD signals?
#!/usr/bin/perl -w
use FileHandle;
use strict;
my (
$chld_pid,
$wait_pid,
$sigchld, # flag for SIGCHLD signals
@tu,
);
sub Handle_SIGCHLD
{
$wait_pid = wait;
$sigchld = 1 if ($wait_pid != $chld_pid);
}
}
$sigchld = 0;
STDOUT->autoflush(1);
$SIG{CHLD} = \&Handle_SIGCHLD;
chdir '/' or die "Cannot chdir to /; RC=$!";
umask 0;
defined($chld_pid = fork) or die "Can not fork; RC=$!";
if (! $chld_pid) {
print 'Sleep to simulate child processing ...', "\n";
sleep 300;
exit;
}
system (`/usr/bin/tapeutil, '-f', '/dev/rmt1', 'mount', '32');
if ($? != 0) { # this is always true
sleep 10;
system (`/usr/bin/tapeutil, '-f', '/dev/rmt1', 'mount', '32');
}
while (! $sigchld) {
print 'Simulating parent processing', "\n";
sleep 30;
}
print 'Child process is no longer active', "\n";
exit;
------------------------------
Date: Thu, 27 Sep 2001 09:38:30 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Werte aus einem Array =?iso-8859-1?Q?l=F6schen?=
Message-Id: <slrn9r4pnm.8ai.mgjv@martien.heliotrope.home>
On Wed, 26 Sep 2001 19:06:02 -0000,
Michael <info@gummipuppen.de> wrote:
> @delete = ('wer1','wert2'); # Zu l"schende Werte
> @val = ('wert1','wert2','wert3','wert4');
>
> Ich möchte alle Werte, die sich in @delete befinden, aus @val löschen.
> Hat jemand eine schnelle Routine für mich ?
Perl FAQ, section 4, question
How do I compute the difference of two arrays? How do I
compute the intersection of two arrays?
Martien
--
Martien Verbruggen |
Interactive Media Division | Little girls, like butterflies, need
Commercial Dynamics Pty. Ltd. | no excuse - Lazarus Long
NSW, Australia |
------------------------------
Date: Wed, 26 Sep 2001 23:29:10 +0100
From: "Jeremy Smith" <removespamjeremyalansmith@netscapeonline.co.uk>
Subject: Win32 Perl - Setting ENV Variables from Command-line
Message-Id: <xBss7.11201$L4.1991228@news6-win.server.ntlworld.com>
Hi everyone!
This is an awkward question, but I thought I'd post here because I can't
think of how to find out information about it on the web.
Next I should mention is that I am using the Win32 platform for Perl, so
this is not specifically a pure Perl question. However, please bear with me.
I am writing a simple web server that runs off a stand-alone computer (say,
a cable modem user, or even a dial-up user). I would like to run Perl
scripts on this server.
I wondered how variables like REMOTE_USER_IP (or somesuch) and
"QUERY_STRING" are actually passed from the server program (which knows the
values of such variables) to the Perl interpreter (which doesn't)? So that
when I run a Perl script from the interpreter, it runs as it would if it
were running on a website.
So the question is: How do I set ENV variables when running a local Perl
script on a local interpreter.
I am running ActivePerl version 5.
Thanks,
Jeremy.
------------------------------
Date: Thu, 27 Sep 2001 11:29:34 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Win32 Perl - Setting ENV Variables from Command-line
Message-Id: <kCvs7.42$ou4.533@wa.nnrp.telstra.net>
"Jeremy Smith" <removespamjeremyalansmith@netscapeonline.co.uk> wrote in
message news:xBss7.11201$L4.1991228@news6-win.server.ntlworld.com...
> Hi everyone!
>
> This is an awkward question, but I thought I'd post here because I can't
> think of how to find out information about it on the web.
>
> Next I should mention is that I am using the Win32 platform for Perl, so
> this is not specifically a pure Perl question. However, please bear with
me.
>
> I am writing a simple web server that runs off a stand-alone computer
(say,
> a cable modem user, or even a dial-up user). I would like to run Perl
> scripts on this server.
>
> I wondered how variables like REMOTE_USER_IP (or somesuch) and
> "QUERY_STRING" are actually passed from the server program (which knows
the
> values of such variables) to the Perl interpreter (which doesn't)? So that
> when I run a Perl script from the interpreter, it runs as it would if it
> were running on a website.
They are passed as environment variables, if they are available.
> So the question is: How do I set ENV variables when running a local Perl
> script on a local interpreter.
The server does it. You need to read the variables to find the content, not
set them.
Maybe you need to ask more in a group about the particular server you are
using?
> I am running ActivePerl version 5.
Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass it
around');
for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
$_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";
------------------------------
Date: Thu, 27 Sep 2001 01:14:12 +0100
From: "Dr Joolz" <jxm96c@hotmail.com>
Subject: Re: XML::Writer question... how to write output to file?
Message-Id: <c8us7.12125$L4.2082189@news6-win.server.ntlworld.com>
This is what I found and works:
// need these 2 both
use XML::Writer;
use IO;
my $filename = $0; // this will find the calling script's filename
e.g. test.pl
$filename =~ s/(\..+)//g; // and strip any file extension so you get test
only
// then now you have an output file with the same name as the script
my $output = new IO::File(">$filename.svg");
my $writer = new XML::Writer(OUTPUT => $output); // this is how u use xml
writer
Cheers, Jules
***24 hours in a day...24 beers in a case...coincidence?***
------------------------------
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 1827
***************************************