[17797] in Perl-Users-Digest
Perl-Users Digest, Issue: 5217 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 29 00:10:29 2000
Date: Thu, 28 Dec 2000 21:10:14 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <978066614-v9-i5217@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 28 Dec 2000 Volume: 9 Number: 5217
Today's topics:
Re: reading multi-line records <mischief@velma.motion.net>
Re: Sending Zero Values from Forms <comdog@panix.com>
SERVER ? <rucus20@hotmail.com>
Re: Syntax for "eq" and "||" <nospam@nospam.com>
Upload dir security shwekhaw@my-deja.com
Re: Upload dir security <joe+usenet@sunstarsys.com>
Re: Upload multi files with same source martinnitram@my-deja.com
Re: Using Sendmail with Perl and CGI (David Efflandt)
Re: Using Sendmail with Perl and CGI <mbudash@sonic.net>
Re: Where can I get CRYPT for DOS/WIN? <virtualvat@yahoo.com>
Re: Win32::ODBC - How to test for NULL? (MSSQL7) <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 29 Dec 2000 02:52:02 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: reading multi-line records
Message-Id: <t4nv2irfv8sg49@corp.supernews.com>
Doug Kite <dkite@co.lenoir.nc.us> wrote:
> How do I set $/ so that it will read three lines for each record?
You can't.
> There are no blank lines separating records, and there is no consistent
> text at the beginning of each record (like a header), and the records
> are not all the same length.
What you need to do, as others have pointed out, is to grab the lines
and either combine them or deal with them using regexen.
Tad mentioned something similar to this :
###-----###
while(<>) {
$_ .= <>;
$_ .= <>;
}
###-----###
Someone else mentioned something closer to this:
###-----###
while(<>) {
if(/pattern1/) {
}
if(/pattern2/) {
}
}
###-----###
I have used - as many people have - something similar to the code
immediately above when processing RADIUS detail logs. It seldom pays
to actually append multiple lines when doing that, though, and it
is done to select what type of data the line represents. This could
be a useful thought to keep in mind when considering how to append
lines into a single record. Sometimes you don't have that need,
even when it seems at first you do. If you really do, read further.
I'd like to point out that you can take other approaches to appending
multiple lines into a single record.
A more flexible version of Tad's idea is to use a variable somewhere that
lets you configure the line length of your records.
###-----###
$lines_per_record = 3; ### number of lines per record, of course
$curr_line = 0; ### current line in the record
$record = '';
while(<>) {
$record .= $_; ### add the current line from file to the record
if ( $curr_line == $lines_per_record ) { ### if this line is the last
### to be added to the record
$curr_line = 0; ### reset which line of the record we're on for next
### time
&process_data($record); ### call a subroutine (or replace this call
### with code) to process the record...
$record = ''; ### initialize record for the next time
}
}
###-----###
A way to combine some of the robustness and flexibility of the second
method with some of the efficiency of the first is to only use a regex
when dividing between one record and another. This might not save you
much if you have to apply a regex to the whole record later, but if you
are interested in breaking the file into records, then using split() or
something similar to get just certain fields from the record, you might
save some time.
###-----###
$record = '';
while(<>) {
if ( /^[A-Z]+/ ) { ### or whatever regex assures you it's a new record...
### process the existing record when you see a new one
if ( $record ) { ### only process if the record has a value, such as after
### we see the first start - we need to see the second
### start to process the first
&process_record($record); ### process the record
$record = ''; ### reset the record, because we're starting a new one
}
}
$record .= $_; ### add the current line to the record. In the case of a new
### record, we've already cleared the old one above.
}
###-----###
I use the above method often. It comes in handy, for example, when counting
actual statements in a C source. (Keep in mind that C separates statements by
the ending semicolon, no matter how many lines there may be in the source file.)
Of course, for something like C you must take quoted characters into account,
too. Counting blocks can be done in a similar manner, but with hairier details
considering nesting. Counting statements in C source is probably a bad example,
since yacc and lex would be a more suited (although extremely overblown) solution
for that.
> Sample data follows (3 records):
> UO-14
> 1 20437U 90005B 00362.20357791 .00000470 00000-0 19619-3 0 5856
> 2 20437 98.3860 62.5557 0011455 8.8249 351.3133 14.30607735570466
> RS-10/11
> 1 18129U 87054A 00361.97069404 .00000149 00000-0 14658-3 0 8848
> 2 18129 82.9245 6.0084 0010119 242.2465 117.7666 13.72539066677015
> STRV 1C
> 1 26610U 00072C 00348.77010174 .00000229 00000-0 00000-0 0 125
> 2 26610 6.3262 237.9809 7347700 194.4901 123.3033 1.99965837 563
> Each record is three lines long, but there are no spaces, blank lines or
> anything. Can $/ be set to grab a certain number of lines?
No, it can't. Hopefully, my solutions above will be helpful. If not, I'm
sure Tad or someone
Chris
--
Christopher E. Stith
Disclaimer: Actual product may not resemble picuture in ad in any way.
------------------------------
Date: Thu, 28 Dec 2000 16:38:46 -0800
From: brian d foy <comdog@panix.com>
Subject: Re: Sending Zero Values from Forms
Message-Id: <comdog-A671F9.16384628122000@news.panix.com>
In article <92e371$8eq$1@nnrp1.deja.com>, georgebailey@my-deja.com
wrote:
> When I parse that form in myscript.pl, and ask it to print out
> $Form{'Item Zero'} I get nothing -- or rather, I get zero characters,
> not the number zero.
> I'm sure I'm missing something obvious. I used the parse_form
> subroutine from FormMail.pl, one of the scripts from Matt Wright.
ah - there's the problem - the buggy programming of Matt Wright
which endures even until now despite the fact that he knows
that there are problems and refuses to fix them.
do not use his stuff.
--
brian d foy - mod_perl hacker for hire <comdog@panix.com>
------------------------------
Date: Thu, 28 Dec 2000 21:40:51 -0800
From: "Rucus20" <rucus20@hotmail.com>
Subject: SERVER ?
Message-Id: <t4nul2ravdaq44@corp.supernews.com>
I have a server that runs version 1.00.000 of a chat program.
I was wondering if anyone can tell me how i can spawn mini servers of the
same
process.
SERVER -> ClientA
-> ClientB
-> ClientC
IS NOW RUNNING ON VIRTUAL TERMINALS ON MY LINUX BOX
I WANT
server -> CLIENTA -> CLIENTB -> CLIENTC
or IS THERE A WAY I CAN BIND A CLIENTS COMPUTER TO MINE SO THAT WE CAN
TRANSFER FILES IN A DIRECTORY.
PRINT "( LOTS OF QUESTIONS..............NEWBIE(SORTOF));";
------------------------------
Date: 29 Dec 2000 04:10:24 GMT
From: The WebDragon <nospam@nospam.com>
Subject: Re: Syntax for "eq" and "||"
Message-Id: <92h2rg$ssk$0@216.155.32.187>
In article <92g3m7$sl1$1@mamenchi.zrz.TU-Berlin.DE>,
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
| The WebDragon <nospam@nospam.com> wrote in comp.lang.perl.misc:
| >In article <3a486ebf.56fd$233@news.op.net>, mjd@plover.com (Mark-Jason
| >Dominus) wrote:
|
| > | If Damian's Quantum Superpositions thing goes into Perl 6, you'll be
| > | able to write
| > |
| > | if ($in{'Contact_Country'} eq
| > | any("Australia","Canada","UK"))
| > | {
| > | ...
| > | }
| >
| >indeed.. looks *quite* nice, but I've run into a few things in 5.004
| >(MacPerl) that I've mailed him about and hope to see an update for
| >soonish. (failing some test cases, etc)
|
| This public complaint about Damian's maintenance is in very bad style.
|
| I find it hard to believe you posted that, but I don't see how your
| paragraph can be read otherwise.
YOU read far too much into what I said.. did I press a little hot button
for you or something?
I ONLY JUST mailed him within the past few days.
heh, dude, take a vacation or something :)
--
send mail to mactech (at) webdragon (dot) net instead of the above address.
this is to prevent spamming. e-mail reply-to's have been altered
to prevent scan software from extracting my address for the purpose
of spamming me, which I hate with a passion bordering on obsession.
------------------------------
Date: Fri, 29 Dec 2000 04:20:26 GMT
From: shwekhaw@my-deja.com
Subject: Upload dir security
Message-Id: <92h3e3$ivs$1@nnrp1.deja.com>
How can we overcome the risk of 777 permission of an upload dir.
I have to setup a page which has feature that professor can upload
files who is auth-user and these files should be able to be viewed by
students. All above give me no option to create that 777 permission
under any path rather www which is accessable by anyone anyhow.
Please suggest me what should I do.
Thank you.
shwekhaw
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 29 Dec 2000 00:03:30 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Upload dir security
Message-Id: <m38zoz95ul.fsf@mumonkan.sunstarsys.com>
shwekhaw@my-deja.com writes:
> How can we overcome the risk of 777 permission of an upload dir.
> I have to setup a page which has feature that professor can upload
> files who is auth-user and these files should be able to be viewed by
> students. All above give me no option to create that 777 permission
> under any path rather www which is accessable by anyone anyhow.
> Please suggest me what should I do.
This is not a Perl-related issue. It's either cgi or web-server
related, so you should ask it in an appropriate newsgroup.
To help you figure out which newsgroup would be appropriate,
ask youself a few questions:
0) What OS is the server running on? (Unix, Mac, etc.)
1) What type of web server is it? (Apache, IIS, etc.)
2) What type of software is handling the uploads?
(httpd server software like frontpage or a perl CGI script,
an ftpd server, rsync/scp, etc.)
3) Is the problem a server/OS configuration issue, or is it a
CGI programming issue? (my guess is the former)
Try to answer these to the best of your ability, and you'll
have some idea which newsgroup will be most useful for
your question.
Surely this one isn't it.
HTH
--
Joe Schaefer
------------------------------
Date: Fri, 29 Dec 2000 03:26:22 GMT
From: martinnitram@my-deja.com
Subject: Re: Upload multi files with same source
Message-Id: <92h08o$gg2$1@nnrp1.deja.com>
Thx a lot for all help.
..deleted
> What code did you use to arrive at your findings? There is no way
> to know how you managed this without posting the offending perl,
> HTML, and CGI.pm version. IIRC, there is an old, broken browser
> that is capable of "compressing" duplicate file uploads, but modern
> browsers should work fine.
the machine config is: (from perl -V)
Perl: perl5 (5.0 patchlevel 4 subversion 5)
OS: RH Linux5.2 (osvers=2.0.36)
And how to find the CGI.pm version?
> However, there are problems with the dual nature of the
> upload fields. If you `use strict', then Perl will com-
> plain when you try to use a string as a filehandle. You
> can get around this by placing the file reading code in a
> block containing the `no strict' pragma.
> The documentation continues:
>
> More seriously, it is possible for the remote user to type
> garbage into the upload field, in which case what you get
> from param() is not a filehandle at all, but a string.
> To be safe, use the upload() function (new in version
> 2.47). When called with the name of an upload field,
> upload() returns a filehandle, or undef if the parameter
> is not a valid filehandle.
>
> $fh = $query->upload('uploaded_file');
> while (<$fh>) {
> print;
> }
>
> This is the recommended idiom.
>
Seem the current using version don't support $query->upload, as the
error log show:
Undefined subroutine CGI::upload
> It seems you are not using the recommended idiom, and also are not
> using strictures. Hence you pay a price by discovering undocumented
> misbehavior. Newer CGI.pm's behave better since $q->param returns
> an overloaded filehandle object instead of a symref, but you'd have
> to read the documentation (or the source :) to find out.
Also, pay for the lazy, bcoz just find in perl.com and missed the
long doc for man and perldoc. :~~~
Again, thx all help and seem found the hint to solve it.
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Fri, 29 Dec 2000 01:32:47 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Using Sendmail with Perl and CGI
Message-Id: <slrn94nqeh.rhh.efflandt@efflandt.xnet.com>
On Thu, 28 Dec 2000, Geoff Soper <g.soper@soundhouse.co.uk> wrote:
>I am interested in using Sendmail through Perl in a CGI context. I see the
>item in the FAQ about 'opening' Sendmail and writing headers and body into
>it but would like more information on this. I have looked at
>www.sendmail.org but after searching can't find information on the various
>headers that I can use. I'm particularly interested in how to use the BCC
>header (if I can).
>Could somebody point me in the right direction?
See 'man sendmail' for sendmail options. Typically the -t option is used
to parse recipients from headers passed to it. A Reply-To: header is
suggested in case your webserver sends mail From: nobody. Don't forget
blank line (or double newline) ending last header line.
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
use CGI qw/:standard/
print header,start_html('Mail Result'),h1('Mail Result'),hr,p;
my $sendmail = '/path_to/sendmail';
my $me = 'me@some.domain'; # note single qoutes
my $bcc = 'me@other.domain';
open (MAIL, "| $sendmail -t") || die "Can't open sendmail: $!";
print MAIL "From: $me\nTo: ", param('email'), "\nReply-To: ",
param('email'), "\nBCC: $bcc\nSubject: Something wonderful\n\n",
"This is the msg body\n";
close MAIL # wait for sendmail to finish
or die $! ? "Error closing sendmail: $!"
: "Exit status $? from sendmail";
print "Mail appears to have been sent",end_html;
--
David Efflandt efflandt@xnet.com http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: Thu, 28 Dec 2000 17:47:40 -0800
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Using Sendmail with Perl and CGI
Message-Id: <mbudash-307C50.17474028122000@news.pacbell.net>
In article <4a342dd848g.soper@soundhouse.co.uk>, Geoff Soper
<g.soper@soundhouse.co.uk> wrote:
> I am interested in using Sendmail through Perl in a CGI context. I see the
> item in the FAQ about 'opening' Sendmail and writing headers and body into
> it but would like more information on this. I have looked at
> www.sendmail.org but after searching can't find information on the various
> headers that I can use. I'm particularly interested in how to use the BCC
> header (if I can).
> Could somebody point me in the right direction?
one way:
open (MAIL, "| /usr/lib/sendmail -t"); # use *your* sendmail location
print MAIL "To: to_address\@domain.com\n";
print MAIL "From: from_address\@domain.com\n";
print MAIL "Bcc: first_bcc_address\@domain.com,
second_bcc_address\@domain.com\n";
print MAIL "Subject: Here's the message subject\n";
print MAIL "\n";
print MAIL "message body here\n";
close MAIL or die ("pipe to sendmail didn't work! child error: $?");
hth-
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: Fri, 29 Dec 2000 04:26:36 +0200
From: "Vitaly Tkachenko" <virtualvat@yahoo.com>
Subject: Re: Where can I get CRYPT for DOS/WIN?
Message-Id: <92h4ca$6vcn4$1@ID-19904.news.dfncis.de>
> Studio 51 (leekembel@hotmail.com) wrote:
> : "Tad McClellan" <tadmc@metronet.com> wrote...
> : > Vitaly Tkachenko <virtualvat@yahoo.com> wrote:
> : > >It just doesn't work correctly.
> : >
> : > Yes it does.
> :
...
> Anyway, if you need a replacement, as always, look in CPAN. The module
> is called Crypt::UnixCrypt. Quoting from the README:
>
> Crypt::UnixCrypt - perl-only implementation of the crypt(3) function.
oh great thanx!!
--
/ VirtualVAT /
------------------------------
Date: Fri, 29 Dec 2000 03:42:44 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Win32::ODBC - How to test for NULL? (MSSQL7)
Message-Id: <3A4C094B.6C11CEB9@rochester.rr.com>
Mike Donaldson wrote:
>
> How can I determine the nullness of a value in the result
> set of a query made through the Win32::ODBC package? E.g.
> I select from a table with a nullable column and desire to
> know if one of the fields is null. Currently, with
> Win32::ODBC I cannot distinguish null fields from blank
> (empty string) fields in a resultset. They are certainly
> different beasts within the database itself. I would like
> to accomplish this without changing the SQL statement
> (e.g. adding "IsNull"). Sample script below.
>
> I have scoured the Win32::ODBC doc and searched the Deja
> archives for an answer to this and have come up with nothing.
> Is there no hope of passing NULLness through the layers of
> ODBC, Win32::ODBC, and perl?
>
> My technical environment: MSSQL 7.0, perl 5.005_03 (ActiveState
> build 522), NT 4.0, Microsoft SQL Server ODBC driver 3.70.08.20
>
> Givens:
>
> MSSQL7 table "tCustomer" created as follows:
> CREATE TABLE tCustomer
> (FirstName varchar (35) NULL)
>
> The table contains a single row with:
> FirstName=NULL (truly NULL)
>
> The output of this script is:
> FirstName is Empty String
>
> I WANT the output of this script to be:
> FirstName is NULL
>
> Thanks!
> -Mike. (mrd1968@my-deja.com)
>
> use Win32::ODBC;
>
> $db = new Win32::ODBC("DSN=Whatever;UID=;PWD=");
> $sql = "SELECT FirstName FROM tCustomer";
> die $db->Error() if $db->Sql($sql);
> $db->FetchRow();
> print "FirstName is Empty String\n" if ($db->Data("FirstName") eq "");
> print "FirstName is Not Defined\n" if ( ! defined $db->Data
> ("FirstName"));
> print "FirstName is Something\n" if ($db->Data("FirstName"));
>
> #print "FirstName is NULL\n" if ( ?? WHAT CAN I DO HERE ?? );
>
> $db->Close();
> exit 0;
...
Hmmmm...maybe you should consider using DBI to interface with your
database. It returns NULL as undef, at least for many drivers. I don't
know about the DBD::ODBC driver, though.
--
Bob Walton
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 5217
**************************************