[9348] in Perl-Users-Digest
Perl-Users Digest, Issue: 2943 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 23 07:07:28 1998
Date: Tue, 23 Jun 98 04:00:37 -0700
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 Jun 1998 Volume: 8 Number: 2943
Today's topics:
ANNOUNCE: max. entropy modeling software <terdoest@cs.utwente.nl>
argc and argv <Robert.Rehammar@emw.ericsson.se>
Re: Curses module - need help <rra@stanford.edu>
Re: Finding size of JPEG images in Perl <ml568366@silab.dsi.unimi.it>
Re: Flames.... (Ilya Zakharevich)
Re: Flames.... <rra@stanford.edu>
Re: How can I get the IP-Number & the Remote_Host Name luong@my-dejanews.com
Re: How can I get the IP-Number & the Remote_Host Name luong@my-dejanews.com
Re: How can I get the IP-Number & the Remote_Host Name <hauk@forumnett.no>
Re: how do I get directory structure disk space used? <admin@bwsd.com>
how to write CGI scripts to connect form in HTML to MS <buranee@gte.net>
Re: More Complete Delete Example (Martien Verbruggen)
Re: More Complete Delete Example <ebohlman@netcom.com>
Re: Pat space doesn't change in nested whiles <ebohlman@netcom.com>
readling a file <Robert.Rehammar@emw.ericsson.se>
Re: readling a file <hauk@forumnett.no>
Re: readling a file <hauk@forumnett.no>
Re: readling a file <dlaser@ermine.ox.ac.uk>
Remove blank too much lines from a text file <zehrer@dialup.nacamar.de>
rmdir and Windows NT 4.0 <Kari.Marttila@tieto.com>
Re: RTF parsing (Andy Wardley)
Re: Sending files via mail in perl <rra@stanford.edu>
Re: Sending files via mail in perl <rra@stanford.edu>
Simple, efficient way of checking whether $VAR is an el <croten@big.aa.net>
Re: Simple, efficient way of checking whether $VAR is a <ebohlman@netcom.com>
system() and security again (Marc Haber)
Re: system() and security again <rra@stanford.edu>
Taint again (Marc Haber)
Re: Taint again <rra@stanford.edu>
Weekdays <-> Dates <hauk@forumnett.no>
Re: Weekdays <-> Dates <ebohlman@netcom.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 23 Jun 1998 11:38:46 +0200
From: Hugo ter Doest <terdoest@cs.utwente.nl>
Subject: ANNOUNCE: max. entropy modeling software
Message-Id: <358F77A6.B85FE24@cs.utwente.nl>
Maximum entropy modeling (MEM) is a very general technique, and suitable
for problem solving in a wide range of research areas: natural language
processing, economics, physics, etc. Because free software for MEM seems
to be missing, I implemented the Improved Iterative Scaling algorithm,
and the Field Induction Algorithm as defined in:
Stephen Della Pietra, Vincent Della Pietra, and John Lafferty,
Inducing features of random fields,
In: Transactions Pattern Analysis and Machine Intelligence,
19(4), April 1997
You can find the software (written in Perl) at:
http://wwwhome.cs.utwente.nl/~terdoest/mem/
It may be copied only under the terms of the GNU General Public License
(version 2, or later).
Comments, recommendations, and questions are welcome
------------------------------
Date: Tue, 23 Jun 1998 12:46:13 +0100
From: Robert Rehammar <Robert.Rehammar@emw.ericsson.se>
Subject: argc and argv
Message-Id: <358F9584.AEB3E0A2@emw.ericsson.se>
Hi !!
I'm writning a perlscript to use with CGI and the POST method. Now I
need to read the argc and argv (don't know if this is the perl name of
it, but I'm sure that everybody knows what I mean, the parameters sent
to the program...). My question is how do I do this ???
\\Robert Rehammar
------------------------------
Date: 23 Jun 1998 03:00:52 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Curses module - need help
Message-Id: <m3ra0gcu97.fsf@windlord.Stanford.EDU>
bgeer <bgeer@xmission.xmission.com> writes:
> I am using the Curses module & have one problem I haven't overcome yet.
> I need a nonblocking method for interrogating keyboard input. So far,
> my code:
> $data_window->nodelay( 1 ) ;
> $key_value = $data_window->getch() ;
> $data_window->nodelay( 0 ) ;
> if ($key_value != -1) { last ; }
> is close to what I need, but "getch()" returns -1 (no input) or the
> actual character typed when there is input. My problem is this message:
> key value: -1Argument "a" isn't numeric in ne at testkbd.pl line 52.
I'm not overly familiar with the Curses module, but it's common practice
for Perl module interfaces to C libraries to remap the error returns from
the C functions to error returns that are more Perlish. Have you checked
to see if getch() actually returns undef if there's no input rather than
-1? That would have been what I would have done were I the author of the
Curses module.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: 23 Jun 1998 08:31:32 GMT
From: Marco Lamberto <ml568366@silab.dsi.unimi.it>
Subject: Re: Finding size of JPEG images in Perl
Message-Id: <6mnp54$k61$1@pluto.sm.dsi.unimi.it>
>> Is there a publically available routine that would allow me to find the
>> height and width of a JPEG image in Perl?
> Yes; look on CPAN for the Image::Size module (or something like that).
> Hope this helps!
I've written a small routine for it when writing an extension to WPP, an HTML
preprocessor in perl, the URL is http://www.geocities.com/Tokyo/1474/wpp.html
--
//\/\ Marco (LM) Lamberto
e-mail: lm@geocities.com
The Sunny Spot - http://www.geocities.com/Tokyo/1474/
------------------------------
Date: 23 Jun 1998 08:16:29 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Flames....
Message-Id: <6mno8t$n23$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Chip Salzenberg
<chip@mail.atlantic.net>],
who wrote in article <6mmneu$89v$1@cyprus.atlantic.net>:
> According to ilya@math.ohio-state.edu (Ilya Zakharevich):
> >On system with *really helping* help/doc systems
> >there is no need for a *user* to search filesystem
>
> Oh? I know OS/2 has a great help facility (I used OS/2 for a while),
> but that won't help you find all the occurrences of SVf_READONLY in
> the Perl sources. Grepping (with whatever too) *is* a necessary
> computer survival skill. That's just more true for programmers than
> others.
No objection whatsoever. However, note the '*user*' wordy which I
carefully put there. ;-)
Ilya
------------------------------
Date: 23 Jun 1998 02:41:11 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Flames....
Message-Id: <m3zpf4cv60.fsf@windlord.Stanford.EDU>
Stephan Carydakis <steph@hotkey.net.au> writes:
> Here here. What the hell ever happened to COMPASSION.
Tragedy of the commons.
> In closing I would just like to say that alot can be achieved through a
> little compassion and love of your fellow man and it benefits everyone.
Yup. And I think nearly everyone here would agree with you and in fact
says the same thing to themselves from time to time. That part just
doesn't come out in newsgroups, while the frustration does.
It's always been easier to argue on Usenet than to do nearly anything
else.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: Tue, 23 Jun 1998 07:55:53 GMT
From: luong@my-dejanews.com
Subject: Re: How can I get the IP-Number & the Remote_Host Name
Message-Id: <6mnn44$b11$1@nnrp2.dejanews.com>
In article <358E6A6A.FFEBF213@pixelfilm.com>,
Alex T <at@pixelfilm.com> wrote:
>
> Hello...
> How can I get the IP-Number & the Remote_Host Name from a user who is
> running my
> CGI-Application?
>
>
Hi,
Write the $ENV{'REMOTE_HOST'} to a logfile.
Cheers,
Pham Thuc Truong Luong
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Tue, 23 Jun 1998 07:55:53 GMT
From: luong@my-dejanews.com
Subject: Re: How can I get the IP-Number & the Remote_Host Name
Message-Id: <6mnn28$e6e$1@nnrp1.dejanews.com>
In article <358E6A6A.FFEBF213@pixelfilm.com>,
Alex T <at@pixelfilm.com> wrote:
>
> Hello...
> How can I get the IP-Number & the Remote_Host Name from a user who is
> running my
> CGI-Application?
>
>
Hi,
Write the $ENV{'REMOTE_HOST'} to a logfile.
Cheers,
Pham Thuc Truong Luong
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Tue, 23 Jun 1998 10:48:26 +0200
From: Hauk Langlo <hauk@forumnett.no>
To: luong@my-dejanews.com
Subject: Re: How can I get the IP-Number & the Remote_Host Name
Message-Id: <358F6BDA.37B17125@forumnett.no>
$remote_server = $ENV {'REMOTE_ADDR'};
$prevous_url = $ENV {'HTTP_REFERER'};
$remote_host = $ENV {'REMOTE_HOST'};
$client_browser = $ENV{'HTTP_USER_AGENT'};
Hope this helps!
Hauk
------------------------------
Date: Tue, 23 Jun 1998 01:10:50 -0500
From: Beck Web Servers & Design <admin@bwsd.com>
Subject: Re: how do I get directory structure disk space used?
Message-Id: <358F46EA.FE42C0F6@bwsd.com>
So far I've got this, which will do one directory, but I don't know how
to get it to recognize if the entry from a read on an opendir is a
directory and then to loop through the directories.
---snip---
#!/usr/local/bin/perl -w
$total_bytes = 0;
opendir (DIRTOREAD,"/usr/local/etc/httpd/htdocs/directorytoread");
@file = readdir(DIRTOREAD);
print "Content-type: text/plain\n\n";
foreach $file (@file) {
open (FILETOREAD,
"/usr/local/etc/httpd/htdocs/directorytoread/$file");
$bytes = read(FILE, $buf, 1000000);
$total_bytes = ($total_bytes + $bytes);
close FILETOREAD;
}
print "Total bytes is $total_bytes\n";
----snip----
Also, if I try to increase the size of the bytes read (1000000) to
include files larger than 1mb, at some point, the script balks, and I
get the core dumped. How do I avoid this, but yet allow the read to get
all files, regardless of size?
Thanks,
--
Eric Beck, BWSD
http://web-design.net/index.shtml
mailto:erbeck@web-design.net
Phone: 905 436 6814 Fax: 905 725 4023
============================================================
Internet Call Manager - Get Your Calls While Online!
http://internetcallmanager/agents/bwsd
============================================================
BECK WEB SERVERS & DESIGN - WHERE SUPPORT AND SERVICE ARE #1
============================================================
------------------------------
Date: Tue, 23 Jun 1998 03:03:07 -0500
From: Buranee Putprasert <buranee@gte.net>
Subject: how to write CGI scripts to connect form in HTML to MS Access
Message-Id: <6mnn1h$2f5$1@news-1.news.gte.net>
Hi All
Right now I have to develop the web application for my class.
Unfortunately I don't know how to do that. Now I have forms in HTML
format and tables in MS Access. I don't know how to write CGI script
using perl to add, delete, update, and query. If anyone knows how to,
please feel free to give me the answer.
My email is buranee@gte.net.
Thank you in advance
P.S. I want to run this application on Windows 95/NT with MS Web
Server(IIS4)
------------------------------
Date: 23 Jun 1998 06:57:26 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: More Complete Delete Example
Message-Id: <6mnjkm$n1i$1@comdyn.comdyn.com.au>
In article <358F4C03.48E1@geocities.com>,
Luckys <luckys@geocities.com> writes:
> It may delete the input from the associative array but it doesn't seem
> to delete it from the dbm file. Why? This is my question. (Your
> example below doesn't seem to even write the associative array to the
> dbm file.)
Yes it does.
#!/usr/local/bin/perl -w
use strict;
my %dbm;
dbmopen(%dbm, 'test_dbm', 0644) || die "Cannot open dbm file: $!";
$dbm{foo} = 'foobar';
$dbm{bar} = 'also foobar';
foreach (keys %dbm) { print "$_ : $dbm{$_}\n" }
dbmclose(%dbm);
print "Reopening\n";
dbmopen(%dbm, 'test_dbm', 0644) || die "Cannot open dbm file: $!";
print "deleting\n";
delete $dbm{bar};
foreach (keys %dbm) { print "$_ : $dbm{$_}\n" }
dbmclose(%dbm);
print "Reopening\n";
dbmopen(%dbm, 'test_dbm', 0644) || die "Cannot open dbm file: $!";
foreach (keys %dbm) { print "$_ : $dbm{$_}\n" }
dbmclose(%dbm);
OUTPUT:
foo : foobar
bar : also foobar
Reopening
deleting
foo : foobar
Reopening
foo : foobar
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | 75% of the people make up 3/4 of the
Commercial Dynamics Pty. Ltd. | population.
NSW, Australia |
------------------------------
Date: Tue, 23 Jun 1998 09:12:04 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: More Complete Delete Example
Message-Id: <ebohlmanEuzyw4.A49@netcom.com>
Luckys <luckys@geocities.com> wrote:
: It may delete the input from the associative array but it doesn't seem
: to delete it from the dbm file. Why? This is my question. (Your
: example below doesn't seem to even write the associative array to the
: dbm file.)
The reason you can still see the key/value pair if you dump the dbm file
is that when you delete an element from such a file, you don't actually
overwrite the data with blanks or anything, you just remove a pointer to
it. If, for security reasons, you need to destroy all evidence of the
data, you'll need to copy the hash to another tied hash after doing all
the deletions, and then you'll have to figure out how to "wipe" the old
file before deleting it (since when you delete a file, you merely return
the disk sectors it contains to the pool of free space, and The Enemy
could grab hold of this data). How you do the latter is
platform-dependent.
------------------------------
Date: Tue, 23 Jun 1998 09:04:16 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Pat space doesn't change in nested whiles
Message-Id: <ebohlmanEuzyJ4.9o6@netcom.com>
Tom Phoenix <rootbeer@teleport.com> wrote:
: Having said that, I should mention that it's almost always wrong to have
: the diamond operator in two places within the same program. (It can be
Shouldn't that be "within the same *loop*" or "for reading the same file"?
Obviously if a program has to read distinct files line by line for
different purposes, multiple diamond operators are to be expected.
------------------------------
Date: Tue, 23 Jun 1998 10:09:26 +0100
From: Robert Rehammar <Robert.Rehammar@emw.ericsson.se>
Subject: readling a file
Message-Id: <358F70C6.513F3B5E@emw.ericsson.se>
I was readling a file with the following:
open (fil,"file");
@FILE=<fil>;
close fil;
print "@FILE";
The contens of the file loks like:
line one
line two
...
The problem is that when I print it the output loks like:
line one
line two
...
How do I remove this first blank ??
\\Robert Rehammar
------------------------------
Date: Tue, 23 Jun 1998 11:21:28 +0200
From: Hauk Langlo <hauk@forumnett.no>
To: Robert.Rehammar@emw.ericsson.se
Subject: Re: readling a file
Message-Id: <358F7398.1EE6755E@forumnett.no>
Read and learn about the chomp command.
Also check your textfile manually. Look for invisible white space
characters after the last word/ period in each line. Trailing
whitespaces are there even if you do not see them. Don't know if this
will work but try marking the text below and see if you can see what I
mean
Line with no following whitespaces.
Line with 20 following whitespaces.
Notice how the invisible spaces appears in the second line?
Robert Rehammar wrote:
> I was readling a file with the following:
>
> open (fil,"file");
> @FILE=<fil>;
> close fil;
> print "@FILE";
>
> The contens of the file loks like:
>
> line one
> line two
> ...
>
> The problem is that when I print it the output loks like:
> line one
> line two
> ...
>
> How do I remove this first blank ??
>
> \\Robert Rehammar
------------------------------
Date: Tue, 23 Jun 1998 11:23:39 +0200
From: Hauk Langlo <hauk@forumnett.no>
Subject: Re: readling a file
Message-Id: <358F741B.42CF3C7C@forumnett.no>
OOOpps. The spaces where automatically removed from the text. Please
ignore the example I made earlier.
Hauk Langlo wrote:
> Read and learn about the chomp command.
> Also check your textfile manually. Look for invisible white space
> characters after the last word/ period in each line. Trailing
> whitespaces are there even if you do not see them. Don't know if this
> will work but try marking the text below and see if you can see what I
> mean
>
> Line with no following whitespaces.
> Line with 20 following whitespaces.
>
> Notice how the invisible spaces appears in the second line?
>
> Robert Rehammar wrote:
>
> > I was readling a file with the following:
> >
> > open (fil,"file");
> > @FILE=<fil>;
> > close fil;
> > print "@FILE";
> >
> > The contens of the file loks like:
> >
> > line one
> > line two
> > ...
> >
> > The problem is that when I print it the output loks like:
> > line one
> > line two
> > ...
> >
> > How do I remove this first blank ??
> >
> > \\Robert Rehammar
------------------------------
Date: 23 Jun 1998 10:48:01 +0100
From: Rob Hutchings <dlaser@ermine.ox.ac.uk>
Subject: Re: readling a file
Message-Id: <yk3af74tpny.fsf@ermine.ox.ac.uk>
Robert Rehammar wrote:
>
> > I was readling a file with the following:
> >
> > open (fil,"file");
> > @FILE=<fil>;
> > close fil;
> > print "@FILE";
<paraphrase> and got an unexpected space at the start of every line
after the first.
Why did you 'print "@FILE"' rather than 'print @FILE' ?
Try the latter, then look for an explanation of the difference.
Check out "Interpolating array values" in the magnificent documentation.
HTH - Rob
Hauk Langlo <hauk@forumnett.no> replied
>
> Read and learn about the chomp command.
> Also check your textfile manually. Look for invisible white space
> characters after the last word/ period in each line. Trailing
> whitespaces are there even if you do not see them.
What has this got to do with the problem being asked about?
Rob
------------------------------
Date: Tue, 23 Jun 1998 12:55:16 +0200
From: Michael Zehrer <zehrer@dialup.nacamar.de>
Subject: Remove blank too much lines from a text file
Message-Id: <358F8993.6B1782ED@dialup.nacamar.de>
Hi out there,
Beeing not a Perl- Pro I need some advice how I can remove blank lines
from a text file or even reduce a number of blank lines too one. Like in
this example:
------
line1
line2
line3
line4
------
Thanks in advance, Michael
------------------------------
Date: Tue, 23 Jun 1998 10:44:03 +0300
From: Kari Marttila <Kari.Marttila@tieto.com>
Subject: rmdir and Windows NT 4.0
Message-Id: <358F5CC3.7FB1@tieto.com>
Hi
I am using Perl version 5.004_02 in Windows NT 4.0. I am using a simple
Perl script to delete certain directories once a week. Every now and
then some directories are not removed (but no error message is given). I
can see the directories with Windows NT Explorer but if I try to see
what's in there NT gives "access denied" message. Only after rebooting
the NT the directories can be deleted manually. This same phenomena has
occured with two NT machines. I am pretty sure that nobody is trying to
use the directories at the same time. Does anyone has any idea what's
going on? The script is here:
sub deletePictureDir {
my ($dday,$dpath) = @_;
my ($ddir, $subdir, $dfile, @numDirList, $ret);
foreach $ddir (<$dpath\\*>) {
next if (not (-d $ddir)); # Next if not a directory.
@numDirList = split (/\\/, $ddir); # Split directory to elements.
$subdir = (@numDirList)[-1]; # Extract subdir.
next if ($subdir =~ /\D/); # Next if not a numeric directory.
next if ($subdir >= $dday); # Next if Sub dir greater or equal than
limit day.
printStdoutAndLog ("Deleting directory $ddir.");
foreach $dfile (<$ddir\\*.*>) { # First deleting the files in the
directory
next if (not (-f $dfile)); # Next if not an ordinary file.
unlink ($dfile) || printErrorAndDie ("Could not delete file
$dfile.");
}
rmdir ($ddir) || printErrorAndDie ("Could not delete directory
$ddir."); # Then delete the directory
}
}
Thanks,
*******************************************************
Kari
Marttila
Internet: Kari.Marttila@tieto.com
*******************************************************
------------------------------
Date: Tue, 23 Jun 1998 10:06:01 GMT
From: abw@cre.canon.co.uk (Andy Wardley)
Subject: Re: RTF parsing
Message-Id: <Ev01E1.Bwo@cre.canon.co.uk>
Michele Beltrame <mick@io.com> wrote:
>I need a Perl module or function to parse RTF (Rich Text Format) or on
>second choice MS WinWord DOC files.
You and the rest of the world!
RTF is a mind-blowingly hideous format and writing a parser is no mean feat.
To my knowledge, the only fully-compliant RTF parser is Microsoft's own.
Considering how often the format changes (and different versions are often
incompatible with each other), this isn't too surprising.
I've written a very basic RTF tokeniser which splits an RTF input stream
into component parts. It's raw, but it works. You will probably need to
do some work on it to get it to do anything serious.
I'll package it up and upload it to CPAN later today. Look for RTF::Parser.
A
--
Andy Wardley <abw@kfs.org> Signature regenerating. Please remain seated.
<abw@cre.canon.co.uk> For a good time: http://www.kfs.org/~abw/
------------------------------
Date: 23 Jun 1998 02:47:57 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Sending files via mail in perl
Message-Id: <m3wwa8cuuq.fsf@windlord.Stanford.EDU>
Jim Bowlin <bowlin@sirius.com> writes:
> That's right. The way I use SMTP is to connect to the SMTP server
> provided by my ISP, which takes care of the queueing of files, remote
> failures, etc. If you try to connect to my ISP's SMTP server, the
> connection will be refused. I have used both SMTP and sendmail. The
> only difference I have found is that sendmail runs on the local machine
> and SMTP can run either on the local machine or a remote machine. If
> you have a decent connection to the machine running the SMTP server, it
> is as problem free as sendmail regardless of the final destination of
> the email message.
Using sendmail requires that sendmail be functioning on the local system.
Using SMTP requires that the SMTP daemon be functioning on whatever system
you point it at. Evaluate the situation and decide which of these two is
more likely.
There is no one answer. It varies.
In the environment in which I code, it's far more likely that sendmail
will be working than any single remote SMTP server. I *can't* just point
SMTP at localhost because localhost usually isn't running an SMTP daemon
(why should it, it doesn't handle mail -- it just sends mail). It does,
however, have sendmail, handles a queue, handles retry, and so forth.
Remember, your script is already assuming that the machine it's running on
is working, otherwise the script wouldn't be working at all. (Obvious,
yes, but people overlook this.) If you use SMTP and connect to a remote
system, you now have a dependency on *two* systems, not just one. More
chances of something breaking. On the other hand, there are many
situations (not just non-Unix ones either) where the local machine can't
handle mail properly (maybe it's behind a dialup that isn't always
connected and *can't* do proper queuing and retrying). In those
circumstances, SMTP may be better.
Like most programming problems, or problems in life in general, there is
no one right answer. You have to look at the tradeoffs and think it
through.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: 23 Jun 1998 02:53:37 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Sending files via mail in perl
Message-Id: <m3u35ccula.fsf@windlord.Stanford.EDU>
Paul J Schinder <schinder@leprss.gsfc.nasa.gov> writes:
> Use Net::SMTP to relay through either a server on the local machine, or
> a "nearby" server that is reliable, like the SMTP server of your ISP if
> your ISP is good. Then you'd take care of these problems while still
> being able to use platform portable Perl.
Other people have pointed this out, but it bears repeating: Portable code
that runs on both Unix and Windows and Mac and who knows what else is very
impressive, laudible, and valuable, and wholly unnecessary for 80% of what
people write in Perl. Possibly more.
My weekly status report generator isn't portable Perl; why should it be,
when it always runs on my Unix workstation? The program I wrote to
replace Pnews back when I was using trn isn't portable Perl; why should it
be, when it was always being run by a Unix program? The script on my news
server that cleans its newsgroups file periodically isn't portable Perl;
why should it be, when it's already INN-specific and INN only runs on
Unix? My majordomo injection script to allow majordomo to run with qmail
isn't portable Perl; why should it be, when both majordomo and qmail only
run on Unix?
Portability is something to consider when one is determining the design
constraints of the program. That doesn't mean it's a design constraint of
every program, or even most programs. Particularly in a programming
language whose primary use for many people is to write quick tools, not
supported, stable, production applications. (I'm not implying that Perl
can't be used to write production applications; I use it for that all the
time. I am saying that not everything you write is a production
application, nor should it be.)
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: 23 Jun 1998 01:31:03 -0700
From: Charles Roten <croten@big.aa.net>
Subject: Simple, efficient way of checking whether $VAR is an element of set @LIST ?
Message-Id: <xfkn2b4r03c.fsf@big.aa.net>
Yeah, it's probably a _really_ dumb question ... but while a subroutine
for such would be quite simple to write, I hate to reinvent the wheel ..
and I'd bet two dollars ot a donut that this is probably already done
_properly_, in some standard callable routine.
I am really thinking in set-theoretic terms here. And that's the sort
of test I want.
What I'm _really_ after will look like this ...
@LIST = keys (%hash);
if ( $VAR is an element of @LIST ) {
do stuff ;
} else {
scream bloody murder .. the other shoe just dropped ;
}
Thanks in advance...
croten@aa.0SPAM.net
croten@ceiba.0SPAM.netsis.com
--
croten@aa.0SPAM.net |Pursuant to US Code, Title 47, Chapter 5, Subchapter II,
(Charles D. Roten) |227, any and all nonsolicited commercial E-mail sent to
|this address is subject to a download and archival fee of
|$500 US. E-mailing denotes acceptance of these terms.
------------------------------
Date: Tue, 23 Jun 1998 09:22:10 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Simple, efficient way of checking whether $VAR is an element of set @LIST ?
Message-Id: <ebohlmanEuzzCy.AJL@netcom.com>
Charles Roten <croten@big.aa.net> wrote:
: What I'm _really_ after will look like this ...
: @LIST = keys (%hash);
: if ( $VAR is an element of @LIST ) {
: do stuff ;
: } else {
: scream bloody murder .. the other shoe just dropped ;
: }
perlfaq4 describes a couple ways to do this.
------------------------------
Date: Tue, 23 Jun 1998 09:02:56 GMT
From: Marc.Haber-usenet@gmx.de (Marc Haber)
Subject: system() and security again
Message-Id: <6mnr0s$bkb$4@nz12.rz.uni-karlsruhe.de>
Hi!
I am writing a perl program that has to call tar as a subprocess on a
Linux system. That machine is a mail server, so I have to worry about
security. In certain circumstances, system() has to rely on a shell to
invoke a subprocess which could lead to nasty effects securitywise. So
I'd like to avoid calling a shell.
The docs say that system() uses a subshell if shell metacharacters are
contained in the command. I know ";", ">", "<", "|" and "`" as shell
metacharacters. Are there more?
Am I safe if I ensure that the command that I am passing to system()
does not contain metacharacters? What other measures are recommended
by perl wizards?
Any hints will be appreciated.
Greetings
Marc
--
-------------------------------------- !! No courtesy copies, please !! -----
Marc Haber | " Questions are the | Mailadresse im Header
Karlsruhe, Germany | Beginning of Wisdom " | Fon: *49 721 966 32 15
Nordisch by Nature | Lt. Worf, TNG "Rightful Heir" | Fax: *49 721 966 31 29
------------------------------
Date: 23 Jun 1998 03:26:33 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: system() and security again
Message-Id: <m367hsct2e.fsf@windlord.Stanford.EDU>
Marc Haber <Marc.Haber-usenet@gmx.de> writes:
> I am writing a perl program that has to call tar as a subprocess on a
> Linux system. That machine is a mail server, so I have to worry about
> security. In certain circumstances, system() has to rely on a shell to
> invoke a subprocess which could lead to nasty effects securitywise. So
> I'd like to avoid calling a shell.
> The docs say that system() uses a subshell if shell metacharacters are
> contained in the command. I know ";", ">", "<", "|" and "`" as shell
> metacharacters. Are there more?
Yes. "(", ")", "*", "[", "]", "^", and possibly others, depending on your
shell.
> Am I safe if I ensure that the command that I am passing to system()
> does not contain metacharacters?
Probably, but there's a better method. If you look at the documentation
of system(), it refers you to exec(). Under the documentation of exec()
is the following:
If there is more than one argument in LIST, or if LIST is an
array with more than one value, calls execvp(3) with the
arguments in LIST. If there is only one scalar argument, the
argument is checked for shell metacharacters, and if there are
any, the entire argument is passed to the system's command
shell for parsing (this is `/bin/sh -c' on Unix platforms, but
varies on other platforms). If there are no shell
metacharacters in the argument, it is split into words and
passed directly to execvp(), which is more efficient.
So you want to *always* pass system a list unless you're executing a
simple command with no arguments. That way you'll never go through a
shell regardless of what characters are in the arguments to the command.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: Tue, 23 Jun 1998 09:02:55 GMT
From: Marc.Haber-usenet@gmx.de (Marc Haber)
Subject: Taint again
Message-Id: <6mnr0r$bkb$3@nz12.rz.uni-karlsruhe.de>
Hi!
I have the following code fragment that does a "rm -rf".
sub untaint
{
my ($parm) = @_;
if( $parm =~ /^(.+)$/ )
{
return $1;
}
}
sub DelTree
{
my ($target) = @_;
if( ! -e $target )
{
return;
}
if( -f $target )
{
unlink $target; # (1)
return;
}
opendir "dir", $target;
my @directory = readdir "dir";
closedir "dir";
File: foreach(@directory)
{
my $targetname = untaint("$target/$_"); # (2)
if( /^\.|\.\.$/ )
{
next File;
};
if( -d $targetname )
{
DelTree($targetname);
next File;
};
unlink($targetname) or die;
next File;
}
rmdir( $target ); # (3)
}
I am far from being a perl wizard, so if that code contains some
clumsiness, I'd like to know what I could do better. Also, I am still
an apprentice when it comes to Unix security.
This code is destined to run in a taint-checking environment under
Linux. Am I safe to untaint (2) the file names that are read from the
directory since I positively know that a file with that name exists
since I just read the directory? Should I do additional tests?
Also, this code snipped fails if the parameter passed in from the
outside is tainted - either on the unlink at (1) or the rmdir at (3).
I clearly cannot untaint the parameter passed in at the very beginning
since I will be throwing the gained security away again. Which checks
do I have to do before I can safely untaint the parameter that is
passed in to me?
Any hints will be appreciated.
Greetings
Marc
--
-------------------------------------- !! No courtesy copies, please !! -----
Marc Haber | " Questions are the | Mailadresse im Header
Karlsruhe, Germany | Beginning of Wisdom " | Fon: *49 721 966 32 15
Nordisch by Nature | Lt. Worf, TNG "Rightful Heir" | Fax: *49 721 966 31 29
------------------------------
Date: 23 Jun 1998 03:24:04 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Taint again
Message-Id: <m390moct6j.fsf@windlord.Stanford.EDU>
Marc Haber <Marc.Haber-usenet@gmx.de> writes:
> I have the following code fragment that does a "rm -rf".
[...]
> I am far from being a perl wizard, so if that code contains some
> clumsiness, I'd like to know what I could do better.
The major clumsiness is that you're reinventing File::Find for no
particularly good reason. You don't want to do recursive file system
decents yourself; there are far too many problems and boundary cases to
worry about (you're not dealing with symbolic links, for example). Just
use File::Find and let it take care of that for you.
> Also, I am still an apprentice when it comes to Unix security.
I hope you're not giving people a setuid tool to do rm -rf....
> This code is destined to run in a taint-checking environment under
> Linux. Am I safe to untaint (2) the file names that are read from the
> directory since I positively know that a file with that name exists
> since I just read the directory?
Well, there are race conditions involved in that statement, but in general
yes provided that the file names never go anywhere near the shell (in
other words, using them as an argument to rmdir or unlink should be fine,
but doing anything else with them is questionable).
> Also, this code snipped fails if the parameter passed in from the
> outside is tainted - either on the unlink at (1) or the rmdir at (3).
> I clearly cannot untaint the parameter passed in at the very beginning
> since I will be throwing the gained security away again. Which checks do
> I have to do before I can safely untaint the parameter that is passed in
> to me?
What's the code trying to do and how much can you constrain it?
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: Tue, 23 Jun 1998 10:57:09 +0200
From: Hauk Langlo <hauk@forumnett.no>
Subject: Weekdays <-> Dates
Message-Id: <358F6DE5.424CE3BF@forumnett.no>
Hi there. I'm about to make a program which needs to know which day of
the week it is. I have a good idea about how to do it, but it feels like
an unescesary amount of work. If anyone know somewhere I can find a
model on how to do this, or maybe have a subroutine they have made
themselfes, I would really apprecuate to have a look at it. Thanks.
Regards Hauk Langlo
PS: I'm at the moment without PERL books, so there could possibely be
own commands for doing this for all I know. If you know about such
commands, please let me know.
------------------------------
Date: Tue, 23 Jun 1998 09:22:46 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Weekdays <-> Dates
Message-Id: <ebohlmanEuzzDy.AL1@netcom.com>
Hauk Langlo <hauk@forumnett.no> wrote:
: Hi there. I'm about to make a program which needs to know which day of
: the week it is. I have a good idea about how to do it, but it feels like
: an unescesary amount of work. If anyone know somewhere I can find a
: model on how to do this, or maybe have a subroutine they have made
: themselfes, I would really apprecuate to have a look at it. Thanks.
Take a look at perlfaq4; it's got code to do this.
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 2943
**************************************