[19657] in Perl-Users-Digest
Perl-Users Digest, Issue: 1852 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 1 18:10:47 2001
Date: Mon, 1 Oct 2001 15:10:13 -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: <1001974213-v10-i1852@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 1 Oct 2001 Volume: 10 Number: 1852
Today's topics:
Re: procmail-like task in Perl? (Johan Vromans)
Re: splitting a very wide report <Thomas@Baetzler.de>
Re: Uninitialized Value... (rab)
unpack(), etc - programming question (Alex)
URL forwarding (Tana)
Re: URL forwarding <tsee@gmx.net>
Re: URL forwarding <thomas@baetzler.de>
Re: URL forwarding <mbudash@sonic.net>
Re: use Module vs. use module <brian_helterline@hotmail.com>
USEing modules in another directory (RoJo)
Re: USEing modules in another directory (Chas Friedman)
Re: USEing modules in another directory <comdog@panix.com>
Re: warnings with cgi will crash Win32 perl core (Logan Shaw)
Re: What good is the hyphen for named parameters? (Malcolm Dew-Jones)
Re: where is the library files located? <skuo@mtwhitney.nsc.com>
Re: Win/UNIX Perl CGI incompatibility <gnarinn@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 01 Oct 2001 20:28:33 +0200
From: JVromans@Squirrel.nl (Johan Vromans)
Subject: Re: procmail-like task in Perl?
Message-Id: <m2lmiv2p0u.fsf@phoenix.squirrel.nl>
Cynthia Burns <burns_cindy@hotmail.com> writes:
> This is functionality similar to procmail, but
> I want to write my own script to do it.
How about Mail::Procmail?
-- Johan
------------------------------
Date: Mon, 01 Oct 2001 17:11:59 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: splitting a very wide report
Message-Id: <vf1hrtcdd5uphnq9fcb6ne50np680aac59@4ax.com>
On Mon, 01 Oct 2001, Marc Ulrich <mdulrich@unity.ncsu.edu> wrote:
>I've a report output that is very very wide and is better done as three
>individual reports (which will fit on a single page). Line wraps are
>annoying and so is ultrasmall text.
>The only solution I've come up with is to have three output formats and
>do three separate reports. This is kind of awkward. I'd rather do a
>single report but ask it to split it after column x and after column y.
>Is this possible?
You could use unpack:
#!/usr/bin/perl -w
use strict;
my $teststring ="12345678";
my @list = unpack "a2a4a2", $teststring;
__END__
Prints: 12, 3456, 78
Adjust the unpack pattern to your desired with, then read the report
line by line, unpack each line and write out three sub-reports from
$list[0], $list[1] and $list[2].
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: 1 Oct 2001 13:28:46 -0700
From: richardbriggs@att.com (rab)
Subject: Re: Uninitialized Value...
Message-Id: <900b7105.0110011228.7191a096@posting.google.com>
> > why? Is it a coding error or Because the grep didn't pick
> > anything up?
>
> It could be either. (You haven't told us what it's supposed to do or
> what your input looks like.)
>
Welp...what it's doing is grepping the syslog for this error when our
DNS fails to update:
Sep 28 15:12:25 hostname named[20334]: master zone
"domain.subdomain.com" (IN) rejected due to errors (serial 67688)
as well as one other line that contains the words "data error" so the
dual grep is restricted to the word "rejected" and "data error"
IF it finds it, it tests whether to see if this is from the current
HOUR or a previous HOUR...(I only want the current hour in which the
perl script is running to be grepped...since our syslog contains
messages from days and days ago, I refine the array created by the
first grep testing for the current hour...) (all this is accomplished
because I do NOT want to create additional files on the box)
anyhoo...
> > How can I avoid this error if infact @rejec is empty (because
> > no offending lines in the syslog were grep'd)
>
> Check it's length before trying to process it.
>
> if (@rejec) {
> # array is not empty, okay to process
> # ...
> }
So... if (@rejec) means that if the array contains data....peform the
{
commands
}
?
------------------------------
Date: 1 Oct 2001 11:45:40 -0700
From: samara_biz@hotmail.com (Alex)
Subject: unpack(), etc - programming question
Message-Id: <c7d9d63c.0110011045.7a6b68fd@posting.google.com>
Hi,
I'm designing a security system for a department website. The way
I'm thinking of programming it is: Every element on a webpage has a
code according to what permissions a user has to have to access it.
When a user goes to that webpage, his permissions code is compared to
that of each element on the webpage, and if the user doesn't have
enough permissions to access an element, it is just not displayed.
Examples:
user 100
element 100
------
access allowed
user 100
element 110
------
access denied
If you AND two codes and then XOR the result with element code then
you can determine if the user has enough permissions to access the
element. I am having problems with this piece of code that I wrote to
do exactly what is described above:
-----------------------------------------------------
use strict;
use warnings;
my $USER_perm = "100";
my $ELEM_perm = "100";
my $USER_converted = pack "B8", $USER_perm;
my $ELEM_converted = pack "B8", $ELEM_perm;
my $result_one = $USER_converted & $ELEM_converted;
if( $result_one == 0 ){
print("REJECTED-1\n");
} else {
my $result_two = $ELEM_converted ^ $result_one;
if( $result_two == 0 ){
print("ACCEPTED\n");
} else {
print("REJECTED-2\n");
} #if
} #if
-----------------------------------------------------
This doesn't seem to work. First it gives me an error saying that the
value in $result_one is not numeric so I can't use == for comparison.
I supposed I need to unpack() it before I compare it, but after
reading about unpack() in Programming Perl, I'm still not sure how to
do it.
I would really appreciate if someone would look at this code and point
out what's wrong with it and maybe some hints on how to fix it.
Thanks a lot in advance!
Alex
------------------------------
Date: 1 Oct 2001 09:01:59 -0700
From: tana@acedsl.com (Tana)
Subject: URL forwarding
Message-Id: <4294f74d.0110010801.58b56cb4@posting.google.com>
Hi, I am new in Perl programming, I have a simple question:
How do I do page forwarding, I want to call PHP script and pass all
the arguments that perl script received.
thanks
tana
------------------------------
Date: Mon, 1 Oct 2001 19:44:57 +0200
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: URL forwarding
Message-Id: <9paa1m$mj6$04$1@news.t-online.com>
"Tana" <tana@acedsl.com> schrieb im Newsbeitrag
news:4294f74d.0110010801.58b56cb4@posting.google.com...
> Hi, I am new in Perl programming, I have a simple question:
> How do I do page forwarding, I want to call PHP script and pass all
> the arguments that perl script received.
That is not a Perl question in any way.
You print a redirect HTTP header.
You use the 'print' function for that.
You look into HTTP or search google withion 5 minutes to find the exact
string.
Steffen
------------------------------
Date: Mon, 01 Oct 2001 20:16:56 +0200
From: Thomas Bätzler <thomas@baetzler.de>
Subject: Re: URL forwarding
Message-Id: <t6bhrtcto9kuou4r93n5p826h3ukkaslho@4ax.com>
On Mon, 1 Oct 20010, "Steffen Müller" <tsee@gmx.net> wrote:
>"Tana" <tana@acedsl.com> schrieb im Newsbeitrag
>news:4294f74d.0110010801.58b56cb4@posting.google.com...
>> Hi, I am new in Perl programming, I have a simple question:
>> How do I do page forwarding, I want to call PHP script and pass all
>> the arguments that perl script received.
>
>That is not a Perl question in any way.
Actually, that is not true, Steffen :-)
He could be asking for CGI.pm's redirect method. However...
>You print a redirect HTTP header.
is not the proper answer here - read the OP's question again.
He asks specifically about passing along the CGI parameters - and that
makes this question at least a bit interesting.
So far I'm inclined to say that this would involve collecting all POST
parameters and converting them to GET parameters which are passed on
via the redirect() method as part of the target URL.
This approach has many flaws and drawbacks - namely, the way I do it,
POST parameters overwrite GET parameters of the same name. There is
also no support for multi-valued fields because I don't know OTTOH how
they are encoded as GET parameter.
Still, this is a start that the OP can build on.
#!/usr/bin/perl -wT
use strict;
use CGI qw(param);
use URI::Escape;
my $target_uri = "http://localhost/cgi-bin/target.cgi";
my $q = new CGI;
my %conv;
if( defined( $q->url_param() ) ){
foreach( $q->url_param() ){
$conv{ uri_escape( $_ ) } = uri_escape( $q->url_param( $_ ) );
}
}
if( defined( $q->param() ) ){
foreach( $q->param() ){
$conv{ ( $_ ) } = uri_escape( $q->param( $_ ) );
}
}
if( my $get_param = join('&', map {"$_=$conv{$_}"} keys %conv ) ){
print $q->redirect( "$target_uri?$get_param" );
} else {
print $q->redirect( "$target_uri" );
}
__END__
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: Mon, 01 Oct 2001 18:55:29 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: URL forwarding
Message-Id: <mbudash-5E6FFF.11553401102001@news.sonic.net>
In article <t6bhrtcto9kuou4r93n5p826h3ukkaslho@4ax.com>, Thomas Bätzler
<thomas@baetzler.de> wrote:
> On Mon, 1 Oct 20010, "Steffen Müller" <tsee@gmx.net> wrote:
>
> >"Tana" <tana@acedsl.com> schrieb im Newsbeitrag
> >news:4294f74d.0110010801.58b56cb4@posting.google.com...
> >> Hi, I am new in Perl programming, I have a simple question:
> >> How do I do page forwarding, I want to call PHP script and pass all
> >> the arguments that perl script received.
> >
> >That is not a Perl question in any way.
>
> Actually, that is not true, Steffen :-)
>
> He could be asking for CGI.pm's redirect method. However...
>
> >You print a redirect HTTP header.
>
> is not the proper answer here - read the OP's question again.
> He asks specifically about passing along the CGI parameters - and that
> makes this question at least a bit interesting.
>
> So far I'm inclined to say that this would involve collecting all POST
> parameters and converting them to GET parameters which are passed on
> via the redirect() method as part of the target URL.
>
> This approach has many flaws and drawbacks - namely, the way I do it,
> POST parameters overwrite GET parameters of the same name. There is
> also no support for multi-valued fields because I don't know OTTOH how
> they are encoded as GET parameter.
>
> Still, this is a start that the OP can build on.
>
> [snip]
thomas, your solution depends on the fact that the target script is set
up to *accept* GET-style parms to do its appointed job. if not, then the
OP may in fact need to look into the LWP set of perl modules to do the
job, since POST-style redirects are problematic, to say the least.
hth-
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: Mon, 1 Oct 2001 15:03:55 -0700
From: "Brian Helterline" <brian_helterline@hotmail.com>
Subject: Re: use Module vs. use module
Message-Id: <9pap8h$462$1@hpcvnews.cv.hp.com>
"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:05t9rt0ovnler4ctp185g24mvbr2sqie6s@4ax.com...
> So lets assume the module file is actually called "FooBar.pm", and the
> package inside it is called "FooBar".
>
> Perl goes searching for "Foobar.pm", stumbles across "FooBar.pm", and
> since Windows has a case insensitive file system, these are considered
> equivalent. So perl loads and runs it.
>
> Next, it goes searching for the package "FooBar", and more specifically,
> for the sub "import" in it. Perl is case sensitive. The package "FooBar"
> doesn't exist, so it ends there. No error. So nothing is imported, and
> thus the functions that sgould have been recoginzed as coming from your
> module, aren't recognized. That's where the behaviour you see comes
> from.
>
> I can agree that maybe "use" ought to complain if it can't find the
> package, instead of that just the sub "import" is missing. But if
> mainly Windows (and Mac) programmers would benefit from it, I doubt if
> P5P would bother. ;-)
>
So are there any ways to check this short of doing some eval statement?
eval { defined Foobar::import } [or something like this]
------------------------------
Date: Mon, 01 Oct 2001 19:24:42 GMT
From: rojo@mindspring.com (RoJo)
Subject: USEing modules in another directory
Message-Id: <3bb8c2cd.2539121@news.mindspring.com>
I'm learning PERL with the help of a good book and your generous help.
I've succeeded in creating enterprise-level modules for my programs.
They work like a charm, as long as they're in the same directory as
the calling program. Since these modules will relate to several
applications, I want to put them into their own directory. But I can't
figure out the syntax to do so.
The current application program under development is in:
C:\Web_Sites\rjassets\cgi
The enterprise-level modules are in:
C:\Web_Sites\rjapps\cgi
I coded this command near the top of the calling program:
use ..::..::rjapps::cgi::xml_methods;
But the PERL compiler says:
syntax error at file_maint_using_modules.pl line 6, near "use .."
I also tried:
use Web_Sites::rjapps::cgii::xml_methods;
But I then got:
Can't locate Web_Sites/rjapps/cgii/xml_methods.pm in @INC (@INC
contains: C:/Perl/lib C:/Perl/site/lib .) at
file_maint_using_modules.pl line 6.
Can anyone help me with the correct syntax for the USE?
Ron (rojo@mindspring.com)
------------------------------
Date: Mon, 01 Oct 2001 20:09:12 GMT
From: friedman@math.utexas.edu (Chas Friedman)
Subject: Re: USEing modules in another directory
Message-Id: <3bb8cc0b.52431590@news.itouch.net>
On Mon, 01 Oct 2001 19:24:42 GMT, rojo@mindspring.com (RoJo) wrote:
>
>I'm learning PERL with the help of a good book and your generous help.
>I've succeeded in creating enterprise-level modules for my programs.
>They work like a charm, as long as they're in the same directory as
>the calling program. Since these modules will relate to several
>applications, I want to put them into their own directory. But I can't
>figure out the syntax to do so.
>
>
>The current application program under development is in:
>C:\Web_Sites\rjassets\cgi
>
>The enterprise-level modules are in:
>C:\Web_Sites\rjapps\cgi
>
>I coded this command near the top of the calling program:
>use ..::..::rjapps::cgi::xml_methods;
What does this say? (It looks garbled in my newsreader.)
>
>But the PERL compiler says:
>syntax error at file_maint_using_modules.pl line 6, near "use .."
>
>I also tried:
>use Web_Sites::rjapps::cgii::xml_methods;
>
>But I then got:
>Can't locate Web_Sites/rjapps/cgii/xml_methods.pm in @INC (@INC
>contains: C:/Perl/lib C:/Perl/site/lib .) at
>file_maint_using_modules.pl line 6.
>
>Can anyone help me with the correct syntax for the USE?
>
>Ron (rojo@mindspring.com)
You probably need a statement like
use lib 'path_to_lib';
(This will add to @INC.)
and then some
use Module;
statements. (Note the quotes in the use lib statement. It is possible
they should be double quotes for Windows.)
chas
------------------------------
Date: Mon, 01 Oct 2001 16:13:21 -0400
From: brian d foy <comdog@panix.com>
Subject: Re: USEing modules in another directory
Message-Id: <comdog-2A68EF.16132101102001@news.panix.com>
In article <3bb8c2cd.2539121@news.mindspring.com>, rojo@mindspring.com
(RoJo) wrote:
> They work like a charm, as long as they're in the same directory as
> the calling program. Since these modules will relate to several
> applications, I want to put them into their own directory. But I can't
> figure out the syntax to do so.
http://www.perldoc.com/perl5.6.1/lib.html
--
brian d foy <comdog@panix.com> - Perl services for hire
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html
------------------------------
Date: 1 Oct 2001 11:53:27 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: warnings with cgi will crash Win32 perl core
Message-Id: <9pa727$p2n$1@charity.cs.utexas.edu>
In article <3BB861AA.48DDB558@mail.uca.edu>,
Cameron Dorey <camerond@mail.uca.edu> wrote:
>Benjamin Goldberg wrote:
>> It seems that Kira has stopped posting lately. Maybe she was at WTC?
>
>I don't care who she is, don't even joke about that. There _are_ some
>things too sad to mess with.
Thanks for saying that; somebody needed to.
- Logan
--
"In order to be prepared to hope in what does not deceive,
we must first lose hope in everything that deceives."
Georges Bernanos
------------------------------
Date: 1 Oct 2001 12:12:21 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: What good is the hyphen for named parameters?
Message-Id: <3bb8c015@news.victoria.tc.ca>
Bart Lateur (bart.lateur@skynet.be) wrote:
: CGI.pm contains more than one kludge. It uses a similar kludge to see if
: a sub is called as a method or as a function.
: I really don't see why this module, of all modules, is so highly
: recommended.
It is "frequently" recommended, that is not the same as "highly"
recommended.
I think the majority of recommendations suggest using it to _parse_ the
incoming data. The modules other uses produce more diverse opinions.
(BTW, I am very happy that someone has produced this module and made it
available, and I have used it to parse incoming data on many occasions).
------------------------------
Date: Mon, 1 Oct 2001 10:54:57 -0700
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: where is the library files located?
Message-Id: <Pine.GSO.4.21.0110011053210.1706-100000@mtwhitney.nsc.com>
On Sun, 30 Sep 2001, Zimmen Gnauh wrote:
> Can anyone tell me where is CGI.pl usually located in Unix system?
>
Do you mean CGI.pm?
You can try this on the unix commandline:
% perl -MCGI -e 'print $INC{"CGI.pm"}'
--
Cheers,
Steve
------------------------------
Date: Mon, 1 Oct 2001 19:40:43 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Win/UNIX Perl CGI incompatibility
Message-Id: <1001965243.443836213555187.gnarinn@hotmail.com>
In article <iPHm5BA6Qtt7Ewoz@zaynar.demon.co.uk>,
Philip Taylor <philip@zaynar.demon.co.uk> wrote:
>I'm writing some Perl CGI programs to run on a Linux Apache web server,
>but am testing them offline with OmniHTTPD on Windows (and ActivePerl
>5.6.1 build 628). The problem is that scripts such as
(snipped problem due to shebang processing missing on Windows)
I am a fan of the make utility, and usually build my projects
around it.
just have a special target for the unix version that
creates the correct shebang line. (or the other way round)
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 1852
***************************************