[16643] in Perl-Users-Digest
Perl-Users Digest, Issue: 4055 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 18 06:10:36 2000
Date: Fri, 18 Aug 2000 03:10:21 -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: <966593421-v9-i4055@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 18 Aug 2000 Volume: 9 Number: 4055
Today's topics:
perl / unix question arun_rajappa@my-deja.com
Perl code help involving tabs <zommick@aol.com>
Re: Perl code help involving tabs <bwalton@rochester.rr.com>
Re: Pipe on WinNT <pgunreben@lucent.com>
Problem with hash initialization using list (Priit Randla)
Re: problems installing DBD::oracle for oracle-db-acces <gellyfish@gellyfish.com>
Re: problems with Tk and NT4 <jemand@klop.com>
Re: problems with Tk and NT4 <gellyfish@gellyfish.com>
Re: problems with Tk and NT4 <jemand@klop.com>
Re: processing groups of checkboxes <gellyfish@gellyfish.com>
Re: readdir in order by date (Rafael Garcia-Suarez)
Re: Regex Alternation Question <lr@hpl.hp.com>
regex question <alan.zaitchik@mindspring.com>
Re: RSA Encryption <gellyfish@gellyfish.com>
Re: Running Perl-Script as NT-Service <gellyfish@gellyfish.com>
Re: Scalar range operator <bwalton@rochester.rr.com>
Re: Scalar range operator <drayner@atnf.csiro.au>
Re: setting up a cgi directory (Tim Hammerquist)
Re: Sorting is very slow (Anno Siegel)
Re: SUID in perl <gellyfish@gellyfish.com>
Re: The diamond operator. (Colin Keith)
Re: Upload file: Apache/perl - PLEASE HELP!!! (Colin Keith)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 18 Aug 2000 09:22:42 GMT
From: arun_rajappa@my-deja.com
Subject: perl / unix question
Message-Id: <8niv8m$971$1@nnrp1.deja.com>
hi,
i have this problem that seems impossible to crack ! (with the present
system !!)
its like this :
0) i'm writing a set of perl scripts for tracking defects and co-
ordinating projects for our particular system. (i.e, it should work
with the idiosyncracies of the present system)
1) i work on a unix system where multiple people use the same login id
(login id is "shared")
2) i want to write a program that will find out the specific users name
(like "arun" or "raj"... not "shared") and set it in an environment
variable.
3) whenever the user now runs any of my scripts, the script should know
which user ("arun" or "raj") is running the script.
** the only way i can see this being done is :
my program finds the user name, (in some way) spawns off a new shell,
and within the new shell set an environment variable with the users
name, in a way so that when my perl scripts are run, the shell they are
running in will also have the value of that environment variable.
can this be done ??
or can i tackle the problem in some other way, without changing the
system (like getting new login id's for everyone)
thanks,
- arun rajappa
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 17 Aug 2000 21:25:51 -0700
From: "Jordan Zommick" <zommick@aol.com>
Subject: Perl code help involving tabs
Message-Id: <sppeo06k87v64@corp.supernews.com>
Keywords: tab
Suppose I have an ascii document that has some marked up tags identifing
tabs. The example here shows a paragraph with tabs set to 3in and 5in in the
document. The marked up text
would look like:
<P><TABS:3in, 5in>This is text<TAB>More text<TAB>Last Text</P>
Simply converting <TAB> to 5 spaces would end up like
This is text More text Last Text
However, that's not what I'm after. I need the middle set of text to start
at 3 inches and the last set of text to start at 5 inches. So I guess I'd
have to use a fixed font and count the length of string 1 and pad enough
spaces to reach 3inches. Then, count string 1 + padding + string 2 and pad
enough spaces to reach 5 inches. Does this all sound correct? Now, how the
heck would I do that in perl?
------------------------------
Date: Fri, 18 Aug 2000 04:31:23 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Perl code help involving tabs
Message-Id: <399CBC48.6F71DB0C@rochester.rr.com>
Jordan Zommick wrote:
>
> Suppose I have an ascii document that has some marked up tags identifing
> tabs. The example here shows a paragraph with tabs set to 3in and 5in in the
> document. The marked up text
> would look like:
>
> <P><TABS:3in, 5in>This is text<TAB>More text<TAB>Last Text</P>
>
> Simply converting <TAB> to 5 spaces would end up like
> This is text More text Last Text
>
> However, that's not what I'm after. I need the middle set of text to start
> at 3 inches and the last set of text to start at 5 inches. So I guess I'd
> have to use a fixed font and count the length of string 1 and pad enough
> spaces to reach 3inches. Then, count string 1 + padding + string 2 and pad
> enough spaces to reach 5 inches. Does this all sound correct? Now, how the
> heck would I do that in perl?
perldoc -q tabs
--
Bob Walton
------------------------------
Date: Fri, 18 Aug 2000 11:02:12 +0200
From: Peter Gunreben <pgunreben@lucent.com>
Subject: Re: Pipe on WinNT
Message-Id: <399CFB94.C6301626@lucent.com>
Great contribution!!!!
It really works!!!
Some things are really easy,
if you know how to do it!
Thanks a lot
Peter
jason wrote:
>
> open IN, 'somescript.pl |';
>
> WILL NEVER WORK in Windows (at least the current versions) .. you MUST
> put
>
> open IN, 'perl somescript.pl |';
>
> and that (all other things being equal) will work
------------------------------
Date: 18 Aug 2000 11:15:09 +0200
From: priitr.randla@eyp.ee (Priit Randla)
Subject: Problem with hash initialization using list
Message-Id: <399cfe9d@worldnews.eypsise>
Hello
I have a configuration file whose lines look like key=value.
I'd like to initialize a hash using something like this:
($key,$info{$key}) = split /=/ while <> ;
Obviously this does not work and i do understand why($key not evaluated yet
when evaluating $info{$key}).
Is there some way to initialize hash _elements_ using lists as
%hash = ($key1, $val1, $key2, $val2 ) is doing for _entire_ hash?
I'm simply trying to avoid unneccessary temporary variables.
Priit
------------------------------
Date: 18 Aug 2000 08:08:07 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: problems installing DBD::oracle for oracle-db-access
Message-Id: <8nincn$2sj$1@orpheus.gellyfish.com>
On Thu, 17 Aug 2000 10:29:01 GMT rudi_runkel@my-deja.com wrote:
>
>> > I thought that there is no need to install any oracle-software when I
>> > want to connect to a oracle-db via perl on my suse-linux system. Am I
>> > wring or what do I make wrong?
>> >
>>
>> You are wrong - you need the Oracle client libraries.
>>
>>
> And where do I get those libaries?
>
<http://www.oracle.com> at a guess - I would ask in comp.databases.oracle
for a better answer though.
/J\
--
yapc::Europe in assocation with the Institute Of Contemporary Arts
<http://www.yapc.org/Europe/> <http://www.ica.org.uk>
------------------------------
Date: Fri, 18 Aug 2000 09:25:08 +0200
From: "chris müller" <jemand@klop.com>
Subject: Re: problems with Tk and NT4
Message-Id: <8nioa9$rr3$1@pollux.ip-plus.net>
hi
i have installt the neewest vesrion of perl and Tk.
can it bee, that i need to install a C++ compiler?
chris
Ben Kennedy schrieb in Nachricht ...
>
>"chris" <jemand@klop.com> wrote in message
>news:8nglce$1ng$1@pollux.ip-plus.net...
>> hi all
>> i get perl of a NT4 box with sp6 .
>> even when i try to start a perl with use::Tk i get a Dr.Watson.
>> can help me somone ?
>> cu chris
>
>Maybe its a binary incompatibility? Try deleting whatever you have, and
>install the latest version of perl from www.activestate.com, then (while
>connected to the internet) type "ppm install Tk"
>
>--Ben Kennedy
>
>
------------------------------
Date: 18 Aug 2000 08:01:54 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: problems with Tk and NT4
Message-Id: <8nin12$2s5$1@orpheus.gellyfish.com>
On Thu, 17 Aug 2000 14:22:55 +0200 chris wrote:
> hi all
> i get perl of a NT4 box with sp6 .
> even when i try to start a perl with use::Tk i get a Dr.Watson.
Then there must have been a crime. Unfortunately you dont give
enough information for us to solve it - at a guess you are using a version
of Tk that is incompatible with the Perl version you have.
/J\
--
yapc::Europe in assocation with the Institute Of Contemporary Arts
<http://www.yapc.org/Europe/> <http://www.ica.org.uk>
------------------------------
Date: Fri, 18 Aug 2000 10:48:14 +0200
From: "chris müller" <jemand@klop.com>
Subject: Re: problems with Tk and NT4
Message-Id: <8nit64$74n$1@pollux.ip-plus.net>
hi
I use perl v5.6.0 built for MSWin32-x86-multi-thread and the Tk-Modul from
Activestate Tk.zip
chris
Jonathan Stowe schrieb in Nachricht <8nin12$2s5$1@orpheus.gellyfish.com>...
>On Thu, 17 Aug 2000 14:22:55 +0200 chris wrote:
>> hi all
>> i get perl of a NT4 box with sp6 .
>> even when i try to start a perl with use::Tk i get a Dr.Watson.
>
>Then there must have been a crime. Unfortunately you dont give
>enough information for us to solve it - at a guess you are using a version
>of Tk that is incompatible with the Perl version you have.
>
>/J\
>--
>yapc::Europe in assocation with the Institute Of Contemporary Arts
> <http://www.yapc.org/Europe/> <http://www.ica.org.uk>
------------------------------
Date: 18 Aug 2000 08:22:49 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: processing groups of checkboxes
Message-Id: <8nio89$2ua$1@orpheus.gellyfish.com>
On Wed, 16 Aug 2000 16:03:25 -0400 Michael Graham wrote:
> greetings - i have been using the param() method of CGI.pm as follows to
> build a hash of the name/value pairs.
>
> my @names = param();
> foreach $name ( @names ) {
> my $value = param( $name );
> $cgivars{$name} = $value;
> }
>
> i now have a form where four checkboxes have the name ['day'] and
> different values. if more than one checkbox is checked the code above
> only 'sees' only the first 'day'/value pair.
>
Thats because you are only asking to see the first one. Read the CGI
documentation as to what it does in list context in these cases.
/J\
--
yapc::Europe in assocation with the Institute Of Contemporary Arts
<http://www.yapc.org/Europe/> <http://www.ica.org.uk>
------------------------------
Date: Fri, 18 Aug 2000 07:50:06 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: readdir in order by date
Message-Id: <slrn8ppr01.a9m.rgarciasuarez@rafael.kazibao.net>
David Combs wrote in comp.lang.perl.misc:
>Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
>>
>>A little warning here : -C will not get the correct result if you
>>don't prepend the directory to the file name:
>>
>> opendir DIR,$dir or die "Can't read dir $dir: $!\n";
>> for my $file (sort { -C "$dir/$a" <=> -C "$dir/$b" } readdir DIR) {
>> # ...
>> }
>
>(1) OK -- then why does this -C thing exist?
-C gives the inode change time of its argument. See perlfunc.
>(2) if it is a BIG dir, would `ls -t` be faster?
Forking an ls process is usually slower.
>(3) (remind us) why must one prepend the directory/ to the filename,
> in order to use -C?
To get the complete path. Although perl is sometimes magical, it can't
guess the pathnames for you.
--
Rafael Garcia-Suarez
------------------------------
Date: Thu, 17 Aug 2000 22:25:23 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Regex Alternation Question
Message-Id: <MPG.1406689bab59589298ac8f@nntp.hpl.hp.com>
In article <399c7314.1e0e$128@news.op.net>, mjd@plover.com says...
> In article <MPG.14060c11998dfd5398ac8e@nntp.hpl.hp.com>,
> Larry Rosler <lr@hpl.hp.com> wrote:
> >Here's another way, using $+ to identify the match:
>
> No, you've missed the point. You don't want to know what the matching
> substring is; you want to know *which* pattern matched. When the
> patterns are literal strings, then $+ is what you want, but if the
> patterns are anything complicated, $+ is useless.
I didn't miss the point. I think the specification is ambiguous.
It's easy to get the part of $string that was matched by $alt
with $&, but the opposite (which part $pi of $alt matched)
seems to be far more tricky.
And, by no coincidence, all the subpatterns in my example *are* literal
strings. :-)
Besides, $+ is so litle known that any opportunity to present it here
should be embraced.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 18 Aug 2000 00:09:24 -0400
From: "Alan Zaitchik" <alan.zaitchik@mindspring.com>
Subject: regex question
Message-Id: <8nicpe$h37$1@slb7.atl.mindspring.net>
Please excuse if this is very obvious.
I am trying to have a perl CGI script create a file in response to a form
submission. The perl script is in a sibling directory of where the file is
supposed to be created. This is on an NT system, so if the perl code is in
C:\InetPub\wwwroot\myvirtualroot\scripts\myscript.pl, the file would have to
be created in C:\InetPub\wwwroot\myvirtualroot\users. The name of the file
depends on the value of $UID, so what I would like to do is something like
$newfile = "..\\users\\" . $UID . ".html" ;
or
$newfile = "../users/" . $UID . ".html" ;
followed by
open FILEOUT, ">$newfile";
etc. -- except that neither of these works. Why is that? I would have
thought that either the physical or the virtual path would make sense to the
open statement, no? Neither seems to.
Anyway, if I get
$physPath = $ENV{'PATH_TRANSLATED'};
how would I use regular expressions to create the desired file name? I have
tried various combinatiopns to no avail, but I think my problem is that I
find regular expressions very arcane. What I want is to substitute
everything from "scripts" to the end with "users\$UID.html". It should be
straightforward but I cannot get it right.
Any help most appreciated!
Alan
$newfile = "C:\\inetpub\\wwwroot\\testpilot\\users\\".$UID."_main.html";
------------------------------
Date: 18 Aug 2000 07:50:05 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: RSA Encryption
Message-Id: <8nimat$2r7$1@orpheus.gellyfish.com>
On Thu, 17 Aug 2000 16:46:16 +0100 Steven Young wrote:
> I've decided to use RSA to encrypt an HTML form submission in my Perl script
> before writing the data to a file on the web server. The Perl script will
> encrypt the data using a public key and then another script or win32
> application will decrypt the file using the private key combination.
>
> Can anyone point me in the direction of some code / alogrithms to perform
> these encryption functions and to generate a public / private key
> combination? Is there a Perl module which can be used for this and if so, is
> it a module included as standard with Perl 5.x as I need it to run it on
> many different systems.
You will probably be wanting to look at the modules that begin with
Crypt::* - but none of these are standard and I am not sure if they are
available as binaries for Windows. An alternative would be to find a
suitable command line encryption program and use Perl's wonderful IPC
facilities to communicate with it. Gnu Privacy Guard and the module of
a similar name spring to mind.
/J\
--
yapc::Europe in assocation with the Institute Of Contemporary Arts
<http://www.yapc.org/Europe/> <http://www.ica.org.uk>
------------------------------
Date: 18 Aug 2000 07:56:02 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Running Perl-Script as NT-Service
Message-Id: <8nimm2$2rj$1@orpheus.gellyfish.com>
On 17 Aug 2000 17:49:51 +0100 nobull@mail.com wrote:
> "Guenther Degenfelder" <guenther.degenfelder@datev.de> writes:
>
>> Yes. Very ugly. I know...
>>
>> The script should run on Windows NT (and 2K). It should run ALLWAYS (without
>> a user logged in - and without autologon hacks).
>>
>> I can't schedule it. The script will observe any services or applications -
>> the scheduler too...
>>
>> And i can't install LINUX first! ;-)
>>
>> Any hints?!
>>
>> Post it into NT newsgroup???!!!
>
> Someone may someday write a proper NT service Perl module. Problem is
> that for a process to act as a proper NT service necessarily implies
> threads, and what's more the OS creates new threads not the app.
> Until such time as Perl's threading is a bit more stable I don't see
> this happening. (I thought about it last time I needed a Perl script
> to run as an NT service).
>
> Simple solution: SRVANY from the "NT Resource Kit". This shim allows
> an simple EXE (e.g. Perl.exe) to run as a service.
>
I believe that the procedure is documented in the Win32 specific FAQ
that distributes with the Activestate Perl. Also someone posted a very
full exposition of the whole process last year which can be found via
Deja News.
> Note: "NT Resource Kit" = "The bits of NT you need to make it half-way
> usable as an OS but that Microsoft don't want to include in the
> standard release because they can't be bothered to QA them even to
> their usual standards".
And *do not* under any circumstance attempt to use the Perl that comes
with the NT4 Resource kit - it is that old that it remembers when Kylie
Mynogue was still a sweet kid in 'Neighbours'.
/J\
--
yapc::Europe in assocation with the Institute Of Contemporary Arts
<http://www.yapc.org/Europe/> <http://www.ica.org.uk>
------------------------------
Date: Fri, 18 Aug 2000 04:29:29 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Scalar range operator
Message-Id: <399CBBD6.736E9D89@rochester.rr.com>
Dave Rayner wrote:
...
> Can anyone explain the behaviour of the following piece of code?
>
> ---------------------------------
>
> #!/usr/local/bin/perl
>
> open(SUBPROC, "echo|") || die;
> #my $nothing=<SUBPROC>; # uncommenting out this line makes it fail!
> close SUBPROC;
>
> my $res='4';
> my $val=($res==4 .. 0);
> print ($val,"\n"); # Should be 1, the first in the sequence
>
> ---------------------------------
>
> From page 90 of the Camel book, I see that the scalar range operator ..
> returns the sequence number (1 the first time it is true), and appends
> an "E0" if it is the last in a sequence. So the range operator in the
> following should return 1, which it does.
You mean it should return 1E0, since it is the last of the series,
right?
>
> If, however, you uncomment the said line, the range operator returns
> "1E0".
> Anyone know why that is?
>
> Tested on 5.004_04 for sun4-solaris and version 5.004_01 on digital
> unix.
>
> Regards, Dave R.
You are using .. in a scalar context (in spite of the parens you used).
If you want the array context, assign to an array, as in:
my @val=($res==4 .. 0);
Then the behavior will be as you expect. In a scalar context, .. is
paying attention to line numbers in a file, not integers in a sequence,
which explains the behavior you observed.
--
Bob Walton
------------------------------
Date: Fri, 18 Aug 2000 05:44:49 GMT
From: Dave Rayner <drayner@atnf.csiro.au>
Subject: Re: Scalar range operator
Message-Id: <399CCD51.5578F41B@atnf.csiro.au>
Dave Rayner wrote:
>
> Can anyone explain the behaviour of the following piece of code?
>
> ---------------------------------
>
> #!/usr/local/bin/perl
>
> open(SUBPROC, "echo|") || die;
> #my $nothing=<SUBPROC>; # uncommenting out this line makes it fail!
> close SUBPROC;
>
> my $res='4';
> my $val=($res==4 .. 0);
> print ($val,"\n"); # Should be 1, the first in the sequence
>
> ---------------------------------
Ok, I see now - I was thinking $. was the current line number of the
program file, so I could put 0 as the second operator, which would never
be true. Should have RTFM more carefully!!
Dave R.
------------------------------
Date: Fri, 18 Aug 2000 06:36:58 GMT
From: tim@degree.ath.cx (Tim Hammerquist)
Subject: Re: setting up a cgi directory
Message-Id: <slrn8ppn0m.26j.tim@degree.ath.cx>
On Fri, 18 Aug 2000 01:59:01 GMT, cedop@my-deja.com <cedop@my-deja.com> wrote:
> Hello,
>
> can someone please tell me how I set up a cgi-bin directory, so that I
> can execute a perl script from a web page. My system is running linux
> 6.2 (Redhat), and perl is installed.
>
> When I type which perl, I get
> /usr/bin/perl
>
> when I execute a perl script by typing
> perl scriptName.pl
>
> it works fine, but when i try to run the script from the web browser, I
> just get an error page
Assumption #1: You're using Apache 1.3.x server.
Assumption #2: You're getting a 500 server error.
If both of these assumptions is correct, I recommend making sure your
script is sending the correct headers to the browser client.
If you're actually getting a 404 or other such error, then yes, it's
most likely a server config issue.
See the documentation...usually a collection of HTML files within a
directory named 'manual'. If you're installations like mine (Mandrake 7
linux;Apache/1.3.12), look in /home/httpd/html/manual or maybe a
variation thereof.
But again, we're missing important information. I had to make
assumptions, and when stressed-out programmers have to make assumptions,
watch out! =)
Hope this helps,
--
-Tim Hammerquist <timmy@cpan.org>
The optimist thinks this is the best of all possible worlds.
The pessimist fears it is true.
-- Robert Oppenheimer
------------------------------
Date: 18 Aug 2000 08:39:40 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Sorting is very slow
Message-Id: <8nisoc$nq9$1@lublin.zrz.tu-berlin.de>
Abigail <abigail@foad.org> wrote in comp.lang.perl.misc:
>Now, why isn't heapsort implemented more often... ? ;-)
Yes, that's another beauty, especially the implementation presented
in _Programming _Pearls_.
Anno
------------------------------
Date: 17 Aug 2000 21:25:21 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: SUID in perl
Message-Id: <8nhhnh$1e6$1@orpheus.gellyfish.com>
On Thu, 17 Aug 2000 12:35:10 -0500 Lithium wrote:
>
> I've learned perlsec issues inside out, I've secured out server (partially)
> from sperl hacks, and I know quite a bit about tainting, etc... but nothing
> useful so far for actually implementing any of it. I'm not even sure if
> this will allow a non-root-owned script to take on root access when run from
> cgi (so we can do this thing and move on).
>
No it can't. It is not possible for a non-root process to take on root
privilege ordinarily. Only a process with root privilege can set its user
id to an arbitrary value.
> Anyone know where I can go for information on writing what every reference
> refers to as a "setuid script"? Or have a code example, or even just know
> of a script that uses it that I can look at?
You should read the manpage for chmod about how to set the setuid bit on an
executable. In order to change user id within a Perl program you will want
to use the builtin variable $< and $> which you can read about in the perlvar
manpage.
/J\
--
yapc::Europe in assocation with the Institute Of Contemporary Arts
<http://www.yapc.org/Europe/> <http://www.ica.org.uk>
------------------------------
Date: Fri, 18 Aug 2000 06:47:11 GMT
From: newsgroups@ckeith.clara.net (Colin Keith)
Subject: Re: The diamond operator.
Message-Id: <PZ4n5.162$DT4.3993576@nnrp2.clara.net>
In article <8ni5g3$dem$1@nnrp1.deja.com>, johnvert@my-deja.com wrote:
>Greetings,
>
>$Learning Perl$ claims that: "..the diamond operator reads each line of
>file1 followed by each line of file2 and file 3 in turn, returning undef
>when all lines have been read."
>
>In that example's case, "file1", "file2", and "file3" are command line
>arguments given to the script with the diamond operator.
>
>When I make a test script:
>
>#!/usr/bin/perl
>print while (<>);
>
>I run it with no arguments, and then everything I type is echoed back.
>Why is that? If I do give it arguments, it indeed prints them out, but
As you find out if you read on, <> is a synoym for <STDIN> if @ARGV == 0
perldoc perlop
(Sorry, it doesn't have a section name, the first line of the paragraph is:)
"The null filehandle <> is special and can be used to"
>to search perlfaq1 perlfaq2 perlfaq3 etc.. all at once? Sometimes I
>have questions that I feel are in the FAQ, but I can't search through
Run the command "perldoc perldoc"
Look at the description of the -q flag (It only searches the questions btw,
not the answers, use grep for that)
Col.
---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC
------------------------------
Date: Fri, 18 Aug 2000 07:43:20 GMT
From: newsgroups@ckeith.clara.net (Colin Keith)
Subject: Re: Upload file: Apache/perl - PLEASE HELP!!!
Message-Id: <sO5n5.163$DT4.3995652@nnrp2.clara.net>
In article <8nhgqp$ljo$1@nnrp1.deja.com>, The Milner Group, Inc.
<milnergroup@usa.net> wrote:
>As a result I am getting the following error:
>"Premature end of script headers".
That's the result of your script not giving back proper headers to your web
server.
>If I change to GET from POST, I can retrieve the file NAME, but the
>actual body of the text file is not there.
>1. Permissions are 777 on upload dir and cgi script.
That is not a good habit to get into. Permissions should be 0755 at best on
your script. There is no need for your script to be writable by anyone but
yourself.
>3. CGI is executing without error on command-line
But they run in different environments, most notably of which is that you
have to return a valid HTTP header when returning data to the web server.
>#!/usr/local/bin/perl
-w
use strict;
These should all by my() varaibles
> $theext = ".gif";
Extensions mean nothing about the file type or size, they're just naming
conventions.
> my $req = new CGI;
You should get into the habit of writing CGI->new();
> $fileName =~ s!^.*(\\|\/)!!;
If that's the only parsing you're going to do you might find you're in
trouble. It doesn't use the /g switch (!g in this case) so only the first
match will be replaced. You should certainly remove .. too and I would
suggest anything that isn't a character you can type on your keyboard - and
even some of those should go too. Create a file called '-rf' and see how
much fun you have removing it. Try the warez puppy naming conventions and
call the filename ". ".
I would suggest you restrict file names with a couple of regexp's:
# Very restrictive: Has to be at least 1 letter/number followed by .gif
if(!/^([A-Za-z0-9]+)\.gif$/)
# Slightly less: The first character same as above,
# but after that the name can _ - or .
if(!/^([A-Za-z0-9][A-Za-z0-9_\.-]*)\.gif$/)
You might want to go on to allow the filenaming conventions you get on
Win32, such as including (), &, [], spaces etc. But they have problems. To
be honest you might well be better off generating a filename yourself and
storing that in a table along with the 'real' filename, then consulting the
table:
use Fcntl;
use DB_File;
my(%filename_to_real_name);
tie(%filename_to_real_name, 'DB_File', $name_conv_db, O_CREAT|O_RDWR, 0666);
...
$filename_to_real_name{generate_name} = $fileName;
Then any time you want to access it, say another script you can just use
this code, except that you get the value rather than assign it ...
>if ($allowall ne "yes") {
>if (lc(substr($newmain,length($newmain) - 4,4)) ne $theext){
>$filenotgood = "yes";
>if ($filenotgood ne "yes") {
Eww.
if($allow_all && $newmain !~ /\.$theext$/i){
>open (OUTFILE, ">$basedir/$fileName");
No error handling. Try changing it to:
if(!open( .. )){
print header(),
start_html('Error opening file'),
p('An error occurred opening the file'),
p("\"$!\""),
end_html();
exit(0);
}
>print "$basedir/$fileName<br>";
That's probably generating your error, you have to print the headers - at
least the Content-Type, before you can print HTML.
Col.
---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC
------------------------------
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 4055
**************************************