[6868] in Perl-Users-Digest
Perl-Users Digest, Issue: 493 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 17 18:04:28 1997
Date: Sat, 17 May 97 15:00:21 -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 Sat, 17 May 1997 Volume: 8 Number: 493
Today's topics:
[abc.efg.hij].klm.nop.qrs.tuv to [abc.efg.hij.klm.nop (Jessie Yang)
Re: alternatives in reg exp -- is this by design? <rootbeer@teleport.com>
Re: Couldn't reopen stderr ...? <rootbeer@teleport.com>
Re: File Locking <rootbeer@teleport.com>
Re: idea for new for loop construct (Chipmunk)
Re: inclu-OR in regex (Eric Bohlman)
Re: inclu-OR in regex (Ilya Zakharevich)
Re: MacPerl & Applescript (Chris Nandor)
Re: need perl module to get form input <rootbeer@teleport.com>
Re: Notice to antispammers (Wolfgang Schelongowski)
Re: Notice to antispammers (Wolfgang Schelongowski)
Notice to Tom (was: Notice to antispammers) (Wolfgang Schelongowski)
Re: Output directory <rootbeer@teleport.com>
Re: perl and awk <wm_n00@tarrcity.demon.co.gunk>
Re: piping and user input <roderick@argon.org>
Problem installing Perlshop <jvinci@cybergate.net>
Re: Regex problem - removing trailing form input (Chipmunk)
Re: REQ: Perl obfuscator (Chipmunk)
Re: Save Programming? <rootbeer@teleport.com>
search and replace/news group bottom feeders <hansg@escape.com>
Re: Seeding SRAND on WIN32 <rootbeer@teleport.com>
Re: Sorting a hash on output - newbie <sibsib@hotmail.com>
Re: what's this ? "stack dump during die..." <rootbeer@teleport.com>
Re: what's this ? "stack dump during die..." (Ilya Zakharevich)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 17 May 1997 21:47:12 GMT
From: hungi@acs.bu.edu (Jessie Yang)
Subject: [abc.efg.hij].klm.nop.qrs.tuv to [abc.efg.hij.klm.nop]qrs.tuv ?????
Message-Id: <33852755.8592662@news.bu.edu>
[abc.efg.hij]klm.nop.qrs.tuv to [abc.efg.hij.klm.nop]qrs.tuv
[abc.efg.hij]klm.nop.qrs.tuv.xyz to [abc.efg.hij.klm.nop.qrs]tuv.xyz
both possible in the same file,
anybody have any idea how to do this?
i was try to do it by s///g
but couldn't do it,
is there a better way to do it?
if you have the solution, plz send me an email also when you post
reply, thank you very much
guan@wit.edu
------------------------------
Date: Sat, 17 May 1997 13:50:40 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Bart Lateur <bart.mediamind@tornado.be>
Subject: Re: alternatives in reg exp -- is this by design?
Message-Id: <Pine.GSO.3.96.970517134745.995H-100000@kelly.teleport.com>
On Fri, 16 May 1997, Bart Lateur wrote:
> When Perl tries matching alternatives separated with "|", these are
> tried out from left to right. So, if more than one of the alternatives
> would match, Perl takes out the leftmost matching pattern.
Exactly right. As soon as it finds a match, it's done. It will try the
other choices only if something fails.
> So: is this a nice accident, that could possibly change in the future,
> or is this by design?
It's by design. If you think it should be more clearly documented though,
you're probably right. :-) Send your suggestions by using the perlbug
program which comes with perl. Documentation flaws are considered bugs,
too, and the developers want to fix them.
Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: Sat, 17 May 1997 14:06:44 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: libes maurice <libes@com.univ-mrs.fr>
Subject: Re: Couldn't reopen stderr ...?
Message-Id: <Pine.GSO.3.96.970517140547.995J-100000@kelly.teleport.com>
On Fri, 16 May 1997, libes maurice wrote:
> the error returned by the cgi perl script is :
> "Couldn't reopen stderr"
I couldn't find that listed as one of the errors in perldiag(1), so I
think it's not a message from Perl. It may be coming from the shell, or
from another program you're running.
When you're having trouble with a CGI program in Perl, you should first
look at the please-don't-be-offended-by-the-name Idiot's Guide to
solving such problems. It's available on the perl.com web pages. Hope
this helps!
http://www.perl.com/perl/
http://www.perl.com/perl/faq/
http://www.perl.com/perl/faq/idiots-guide.html
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: Sat, 17 May 1997 14:58:47 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Tsoi Tung Yin Tony <eg_tty@uxmail.ust.hk>
Subject: Re: File Locking
Message-Id: <Pine.GSO.3.96.970517145831.995R-100000@kelly.teleport.com>
On 16 May 1997, Tsoi Tung Yin Tony wrote:
> I want to lock up a flock using perl that running on the web, in order
> to prevent multiple access to the data file. What command should I use?
> I have try flock() but it seems wrong. Can anyone help me?
I think you could use the methods in Randal's fourth Web Techniques
column, which explains how to use flock() to avoid problems when multiple
processes need to modify one file. Hope this helps!
http://www.stonehenge.com/merlyn/WebTechniques/
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: 17 May 1997 15:04:47 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: idea for new for loop construct
Message-Id: <5lkhef$qhi$2@dartvax.dartmouth.edu>
In article <337ad07f.21110859@news.ntr.net>
mark@ntr.net (Mark Mills) writes:
> On Wed, 14 May 1997 14:38:22 -0700, Trenton Lipscomb
> <trenton@ssil.uoregon.edu> wrote:
>
> > for(1 .. 5){
>
> > for $it (1 .. $count){
>
> >However, there is a construct that seems natural to me, but is not
> >recognized by the interpreter. It is:
>
> > for(4 x){
>
> >and, similiarly:
>
> > for $it (4 x){
>
> >where $it would be assigned the value of the current iteration of the
> >loop.
>
> Hmm...
> howz about:
> for($i=0; $i<4; $i++) { print $i,"\n"; }
>
> that would have a conflict with above, since what you were doing
> was really the foreach (LIST) [perl has been taking care of you]
How would that have a conflict?
One is:
for (EXP; EXP; EXP) { COMPOUND-STMT }
and the other is:
for VAR (EXP x) { COMPOUND-STMT }
On the other hand, the construction
for $foo (4 x)
doesn't really seem intuitive to me.
I would use either:
for $foo (1 .. 4)
or
for ($foo=1; $foo<=4; ++$foo)
BTW, according to Camel 1, "The 'foreach' keyword is actually identical
to the 'for' keyword, so you can use 'foreach' for readability or 'for'
for brevity."
Chipmunk
------------------------------
Date: Sat, 17 May 1997 20:00:14 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: inclu-OR in regex
Message-Id: <ebohlmanEACCwF.C4L@netcom.com>
Chipmunk (Ronald.J.Kimball@dartmouth.edu) wrote:
: Silly silly silly.
: /a/ && /b/ && /c/;
<pedantic>That's not a regex.</pedantic>
------------------------------
Date: 17 May 1997 21:35:12 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: inclu-OR in regex
Message-Id: <5ll8ag$e8f$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Eric Bohlman
<ebohlman@netcom.com>],
who wrote in article <ebohlmanEACCwF.C4L@netcom.com>:
> Chipmunk (Ronald.J.Kimball@dartmouth.edu) wrote:
>
> : Silly silly silly.
>
> : /a/ && /b/ && /c/;
>
> <pedantic>That's not a regex.</pedantic>
But this is:
/^(?=.*a)(?=.*b)(?=.*c)/s;
Ilya
------------------------------
Date: Sat, 17 May 1997 12:42:14 -0400
From: pudge@pobox.com (Chris Nandor)
Subject: Re: MacPerl & Applescript
Message-Id: <pudge-ya02408000R1705971242140001@news.idt.net>
In article <199705162033476034053@roxboro-168.interpath.net>,
phenix@interpath.com (John Moreno) wrote:
#Thank you very much. It did indeed.
#
#Now as soon as I can get MacPerl to create a file...
Same as in UNIX Perl.
open(D,">path:to:file") || die "cannot create file: $!\n";
We use Mac path conventions in MacPerl, so '/' does not work, you have to
use ':'.
--
Chris Nandor pudge@pobox.com http://pudge.net/
%PGPKey=('B76E72AD',[1024,'08 24 09 0B CE 73 CA 10 1F F7 7F 13 81 80 B6 B6'])
#=============================================================================
signal(i, SIG_DFL); /* crunch, crunch, crunch */
--Larry Wall in doarg.c from the perl source code
#=============================================================================
------------------------------
Date: Sat, 17 May 1997 14:23:59 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Eric Qiu <qiu@software.org>
Subject: Re: need perl module to get form input
Message-Id: <Pine.GSO.3.96.970517142310.995M-100000@kelly.teleport.com>
On 16 May 1997, Eric Qiu wrote:
> Is there any commercially available perl module or some perl module run
> on Linux for sale that reads the entries of a form and stores the
> information in a plain text file?
Have you seen CGI.pm? It comes with perl 5.004, or you can get it from
CPAN. Hope this helps!
http://www.perl.com/CPAN/
http://www.perl.org/CPAN/
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: 17 May 1997 21:51:21 +0200
From: skaranyi@LOCALHOST.ruhr.de (Wolfgang Schelongowski)
Subject: Re: Notice to antispammers
Message-Id: <5ll27p$ohm@xivic.ruhr.de>
In <5k8g6a$q0d@fridge-nf0.shore.net>
nvp@shore.net (Nathan V. Patwardhan) writes:
>Rajappa Iyer (rsi@lucent.com) wrote:
>: > Fair enough. Therefore Tom is putting useless content on a webpage,
>: > and it shouldn't mean anything to you unless someone sends you spam.
>: And what do you suggest I do when that happens? Note that I said when
>: and not if.
>Tolerate. Don't munge your address ... filter instead. In fact, I enjoy
>filtering 200x as much as I might enjoy screwing with my mail header.
You may not believe this, but connectivity costs money outside the
USA, not peanuts. Your advice amounts to "Let them eat Cake" for
people who are billed by connect time and whose rates doubled
a year ago. Some pay over 20 per KB received email.
Harass the spammers, do not defend people aiding the spammers to harass.
--
Wolfgang Schelongowski Check _ALL_ headers before sending email.
By sending unsolicited bulk email to any of my accounts you give me
permission to nuke any of your computers. Ports 135/139 are known.
------------------------------
Date: 17 May 1997 21:54:48 +0200
From: skaranyi@LOCALHOST.ruhr.de (Wolfgang Schelongowski)
Subject: Re: Notice to antispammers
Message-Id: <5ll2e8$oil@xivic.ruhr.de>
In <fl_aggie-ya02408000R3004971738190001@news.fsu.edu>
fl_aggie@hotmail.com (I R A Aggie) writes:
>In article <xnyafmggu5t.fsf@placebo.hr.lucent.com>, rsi@lucent.com wrote:
>+ use. The moment you do this, you are using my resources. When Tom
>+ hands my address on a platter to spambots, he's essentially saying
>+ "use this computer's resource." Is it legal? Yes. Is it ethical? No
>+ way in hell.
>So, TomC is now responsible for spam? heheheheheh
You might have heard that Tom sometimes visits Europe. Some countries
who sufferred under the Nazis take a dim view of people making such
lists. Would you love to see Tom arrested?
--
Wolfgang Schelongowski Check _ALL_ headers before sending email.
By sending unsolicited bulk email to any of my accounts you give me
permission to nuke any of your computers. Ports 135/139 are known.
------------------------------
Date: 17 May 1997 23:05:37 +0200
From: skaranyi@LOCALHOST.ruhr.de (Wolfgang Schelongowski)
Subject: Notice to Tom (was: Notice to antispammers)
Message-Id: <5ll6j1$oql@xivic.ruhr.de>
In <5kd3js$ls7@coranto.ucs.mun.ca>
pdf@morgan.ucs.mun.ca (pAUL dAVID fARDY) writes:
>privacy. You are publishing contact information and you merely
>believe it's not in machine-usable form. If it were unusable, then
>why worry what Tom's "machine" attempts do with it?
I don't know about you but I will never buy from people who
for whatever reasons aid and/or abet spammers. Tom could have
created a script to automatically ping sites of cyberpromo
when receiving spam or forwarding the spam to whatever
Congresscritter to create pressure where it is needed but he
chose to slash out in blind fury:
because you can't keep the spammers off your back. Write your congressman
or something. Meanwhile, all bogus email address will be tracked down,
My congressman? No such being here. Besides, the highest court here
_has_ ruled that anything like UCE is against the law. Only the USA
insists on sending harassing email, harassing because its contents
applies to the USA only.
Had I known some months ago what Tom would do I would never have
bought the new edition of the Camel book - it would have been my
first opportunity to financially harm somebody aiding spammers.
Of course, I will let other people know about Tom's action so they
too can think about what to do. Sorry, Larry and Randal.
[Note F'up]
--
Wolfgang Schelongowski Check _ALL_ headers before sending email.
By sending unsolicited bulk email to any of my accounts you give me
permission to nuke any of your computers. Ports 135/139 are known.
------------------------------
Date: Sat, 17 May 1997 14:09:01 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: dennis@bnr.ca
Subject: Re: Output directory
Message-Id: <Pine.GSO.3.96.970517140703.995K-100000@kelly.teleport.com>
On Fri, 16 May 1997 dennis@bnr.ca wrote:
> I have a script that proceeses a form and put the info into a file
> called comments.htm. Now the file goes to c:\Program Files\perl5\bin
> -directory. I'd like to put it into a different drive and directory.
> What is the syntax I use?
$filename = 'C:/Program Files/perl5/bin'; # or wherever
open OUT, "> $filename"
or die "Can't open '$filename' for output: $!";
Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: Sat, 17 May 1997 20:31:47 +0100
From: Wm <wm_n00@tarrcity.demon.co.gunk>
Subject: Re: perl and awk
Message-Id: <h7KDEWAjegfzEwLs@tarrcity.demon.co.uk>
Sat, 17 May 1997 13:23:49 <337D8735.1132@iil.intel.com>
Allon Henig <ahenig@iil.intel.com> posted...
>Hi,
> I want to do an awk command in a perl program. If it was in the shell I
>would have done:
>
>awk '{FS=".";print $2}' filename
>
>but since I need to use it in the perl program, I need to use the
>'system' command which uses the "" it'self:
>
>system (" awk '{FS=".";print $2}' filename ");
^ ^
>
>this of course causes an error because of too much "" . Do you have any
>suggestions how to overcome this problem ?
Escape, ie place a backslash (\), before the quotes (") inside (see
carats above).
The above is the simple and obvious answer to your question (though
untested, I'm not sure what effect the single quotes'll have), but why
not use Perl to do it rather than awk?
open(F, "filename") || die "Can't open file";
while (<F>) {
($a, $b, $c) = split(/./, $_, 3);
print $b, "\n";
}
close(F);
(also untested) ought to do it and you'll save having to start up awk.
HTH
--
Wm ... did you know? My spell checker wants tarrcity to be atrocity.
To send e-mail change gunk to uk.
If anyone *ever* registers tarrcity.demon.co.gunk let me know.
------------------------------
Date: 17 May 1997 12:16:05 -0400
From: Roderick Schertler <roderick@argon.org>
To: mmackenz@indiana.edu (Mike MacKenzie)
Subject: Re: piping and user input
Message-Id: <pzn2pu9j13.fsf@eeyore.ibcinc.com>
On Fri, 16 May 1997 12:48:49 -0500, mmackenz@indiana.edu (Mike MacKenzie) said:
>
> The problem I'm having is that once standard input is redirected to
> receive the mail message piped to it from elm, I can't get the script
> to switch back to accept input from the keyboard.
Read from /dev/tty directly.
@message = <STDIN>;
open STDIN, '/dev/tty' or die "Can't read /dev/tty: $!";
--
Roderick Schertler
roderick@argon.org
------------------------------
Date: Sat, 17 May 1997 10:45:43 -0300
From: John Vinci <jvinci@cybergate.net>
Subject: Problem installing Perlshop
Message-Id: <337DB686.EAC6D45E@cybergate.net>
I have been installing Perlshop and have run into two problems.
First, whenever a page loads, after all information and graphics are on
the screen it takes forever to finish loading. If you try to order
something before it finishes doing whatever it's doing, it won't let you
go back without a "Data Missing" error message. I assume that this is
just a problem of a slow server.
The other problem is this, after entering all shipping and payment
information, 1 of 2 things will happen when I push the "Submit "
button. Either the form will go blank or I'll get the following message
from the browser: "Document contains no data."
Any help you could give me would be appreciated.
Sincerely Yours,
John Vinci
--
John Vinci -- jvinci@cybergate.net
------------------------------
Date: 17 May 1997 15:21:48 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: Regex problem - removing trailing form input
Message-Id: <5lkiec$qhi$3@dartvax.dartmouth.edu>
In article <d4ldl5.to3.ln@localhost>
tadmc@flash.net (Tad McClellan) writes:
> Chipmunk (Ronald.J.Kimball@dartmouth.edu) wrote:
> : In article <EA4JLC.C9y@ciba-geigy.ch>
> : david.holmes@bigfoot.com (David M Holmes) writes:
>
> : > my $testurl = "http://www.here.com/path/to/file/me.html?a=b&c=d";
>
> : > $testurl =~ m/.*?(\?.*)/;
>
> : Once you work out the error you mention below, you'll have another one.
> : This line sets $testurl to 1 if the match is successful, '' if not,
> ^^^^^^^^^^^^^^^^^^^^^^^
>
> -----------------
> #! /usr/bin/perl -w
>
> my $testurl = "http://www.here.com/path/to/file/me.html?a=b&c=d";
>
> $testurl =~ m/.*?(\?.*)/;
>
> print "$testurl\n";
> -----------------
>
> $testurl looks unchanged to me... ;-)
Doh, I messed up again. I guess I was reading that as
$testurl = $testurl =~ m/.*?(\?.*)/;
Thanks for correcting me on that.
Chipmunk, who has to stop replying to posts in clpm at 2am.
------------------------------
Date: 17 May 1997 14:54:29 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: REQ: Perl obfuscator
Message-Id: <5lkgr5$qhi$1@dartvax.dartmouth.edu>
In article <5lfj0o$stq@due.unit.no>
Salve J Nilsen <sjn@pvv.ntnu.no> writes:
> And then, Chipmunk suddenly uttered...
> > In article <5l8epe$hll@due.unit.no>
> > Salve J Nilsen <sjn@pvv.ntnu.no> writes:
>
> > > # single out the first line - if it begins with #!
> > > s/^(\#\!.*?[\n\r])/\n/s;
> > > $head = $1 || "";
> > Why the [\n\r]? At the very least, you might want to match \n without
> > a \r.
>
> [\n\r] is a character class, so when I write [\n\r] it'll match either
> \n or \r, but not both (unless I write [\n\r]+ or equivalent)
Duh, I knew that, really I did.
I guess I'd just read one of those posts about dos2unix and was still
thinking about people matching \n\r.
> > The way swap is written right now, I think they'll look like "$msv"
> > > # ##############################
> > > sub swap {
> > > my($name, $hashref, $safe) = @_;
> > > $$hashref{$name} = $msv++ unless ($safe || $$hashref{$name});
> > > warn "SWAP($hashref) -> $name:$$hashref{$name}\n"
> > > if ($DEBUG && !$safe);
> > > return $$hashref{$name}?$$hashref{$name}:$name;
> > > }
>
> > I notice that some of your calls to swap have $safe=0, and others
> > $safe=1 - subroutine declarations vs. subroutine calls, for example.
> > $safe should be the same for identifiers of a given kind - you don't
> > want to rename subroutines where they're defined and not where they're
> > called. :-)
>
> What happens with $safe is supposed to be the following: if $safe is
> set, then we may create new metasyntactical variables in the hash. If
> $safe is unset, we only change the occurences of msv's that we already
> have found (and placed in the hash).
>
> [lengthy but revealing example]
>
> (Was this explanation understandable? :)
Ah... And since you change all the declarations first, and the
calls/uses second... Cool!
Yes, it was. I understand how swap works now.
> > > # ##############################
> > > warn "Pass 4... Whitespace and comments\n" unless $QUIET;
> > > s/(
> > > (?:\\\\)*(?!\\)?([\"\'])[^\1]*(?:\\\\)*[^\\]\1|
> > > ([\"\'])\2|
> > > (?:\\\\)*\\\#.*?$|
> > > \$\#.*?$)|
> > > \#.*?$|
> > > \s{2,}|
> > > [\r\n]|
> > > \#.*?$/$1/gmx;
>
> > Why do you match [\r\n] here, when you matched [\n\r] earlier? (see
> > above)
>
> Yep, see above for my answer. (I think there could be a problem if
> someone used the $^M variable... hmmm.)
Yup, I embarress myself even more by ignoring the [] again.
> > You match to the end of the line after any of the non-comment instances
> > of #. This means that, for example, '$#foo=1; # set size of foo to 1'
> > will not be touched, even though it does contain a comment. I'm not
> > sure of the best way to solve this problem... Looping over each
> > occurence of # might work, though...
>
> what about changing "\$\#.*?$)|" to "\$\#[\w][\w\d]*)|"?
Why didn't I see that? Sigh...
Although, I'm not sure what would happen with $#{$foo} then. I wonder
if it would be enough to just match up to the #, and leave everything
after for the /g.
> > I do think that there will always be some cases that arghify.pl won't
> > be able to handle properly. For example:
> > $foo = "bar";
> > $$foo = "baz";
> > if ($bar eq "baz") {
> > print "Hello world\n";
> > }
> > would be changed to something like:
> > $a = "bar";
> > $$a = "baz";
> > if ($b eq "baz") {
> > print "Hello world\n";
> > }
>
> Not to mention,
>
> print << EOT;
> sub foo {
> print "bar";
> }
> Is a very basic program.
> END
>
> and similar things...
I suppose the only real way to handle all the possibilities would be to
write a full-fledged compiler from perl to obfuscated perl. But that
wouldn'tbe as much fun. :-)
Chipmunk
------------------------------
Date: Sat, 17 May 1997 14:22:11 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Alex `Taker` Pircher <pircher@informatik.tu-muenchen.de>
Subject: Re: Save Programming?
Message-Id: <Pine.GSO.3.96.970517140953.995L-100000@kelly.teleport.com>
On Fri, 16 May 1997, Alex `Taker` Pircher wrote:
> I'm using a perl script as a CGI and within the script I check
> if the file the user inputs in the HTML-Form exists ...
> -----------------------
> if (-d $file) {...}
> open(FILE, $file);
> -----------------------
That's not right; that's checking that it's a directory, rather than a
file, and then opening it in any case. You probably meant this.
unless (-f $file) {
# Some code to complain that there's no such file
}
open FILE, $file
or die "Can't open '$file' for input: $!";
# Or some code to send that complaint to the user
> But now I'm asking me, if this is really a save method of checking
> if a File is there.
Good question! Just because the remote user asks to see /etc/passwd is no
reason to let them do so!
> Shouldn't I remove all special characters first
> like ...
> $file =~ s/"//g;
> $file =~ s/\[//g;
> $file =~ s/\|//g;
> ...
Actually, you should ask yourself what characters (and path names) to
_permit_, and only allow those. Although Unix allows odd characters
(including spaces and newlines) in filenames, you will probably want to
exclude those. Here's one pattern, which intentionally allows only
lowercase.
/^[a-z][a-z0-9_]*(?:\.[a-z0-9_]+)?$/
> And is there a easy way to remove nearly all special characters, so
> that the $file contains only: A-Z a-z / _ -
I'd just complain to the user if they ask for any file that's not
acceptable. Let the user ensure that their filename is valid. But if you
simply want to strip everything but those characters, this should do it.
s#[^-\w/]+##g;
You may also consider turning on taint checking; I recommend it. For more
information, see the WWW Security FAQ and the perlsec(1) manpage.
Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: Sat, 17 May 1997 14:37:31 -0400
From: Hans Gilde <hansg@escape.com>
Subject: search and replace/news group bottom feeders
Message-Id: <337DFAE6.7B45@escape.com>
Thanks to all for the tips on search and replace. I got lots of
responses and realized that I wasn't clear about what I wanted. I was
looking for the function to traverse the file itself, as I already had
the directory traversing done. My purpose is that I have found few text
manipulating tools for the HTML guy who may not know or want to learn
the plethora of scripting languages. Rather than train everyone in my
company or answer twenty questions a day, I'm writing one. I fugure:
Write it in C and compile it everywhere orwrite it in PERL. I will
certainly post the utility and docs when I'm done. If any one knows of
The Wheel which I may be currently be re-inventing I'd love to know.
I have always used and tried to help the spirit of mutual help of news
groups like comp.lang.perl.misc and I would like to say the following:
I feel that there is no form of life lower than those who scour the news
groups for newbies to sell their consulting services to. Never have I
seen so many of these bottom feeders as in comp.lang.perl.misc. I
revieved SEVEN emails offering consulting services since I am posting
from a new email account. I recognize the need for consulting firms to
advertise, but some of the emails that I recieved hinted or indicated
that it would be impossible to do what I was looking for without years
of training in PERL. What BS! The sprit of sharing code and helping
other, including new, programmers is lost to these people. Well, that's
my rant.
Hans Gilde
Immersive Environments, Inc
------------------------------
Date: Sat, 17 May 1997 13:59:50 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Bill Banyai <banyai@llnl.gov>
Subject: Re: Seeding SRAND on WIN32
Message-Id: <Pine.GSO.3.96.970517135105.995I-100000@kelly.teleport.com>
On Wed, 14 May 1997, Bill Banyai wrote:
> Is there a good way to seed the random number generator on a WIN32
> platform?
As of version 5.004, I think that the default seed should be adequate for
most purposes. On the other hand, you're probably not using 5.004 yet. :-)
> An associated question is how to retrieve the time; in particular, how
> to deal with the prompt that follows the display of the time.
Don't bother. Calling the time program on Windows machines requires you to
go through more contortions than a flea-infested Gumby at a Frug festival.
Instead, you can use something like srand(time) to do it directly. If your
program might be called several times during the same second, you may need
to do something more than this.
Of course, if you just need the current date and time in a human-readable
form, try this.
$date = localtime;
Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: Sat, 17 May 1997 13:11:44 -0400
From: Scott Blanksteen <sibsib@hotmail.com>
Subject: Re: Sorting a hash on output - newbie
Message-Id: <337DE6D0.E6459429@hotmail.com>
Bruce McGuire wrote:
> I am trying to sort a hash (names and counters) by the value of the key.
>
> ie I would like output such as:
> Alpha 034
> Alphas 433
> Beta 001
> Deltas 991
Take a look at
<http://www.perl.com/perl/everything_to_know/sort.html>
Scott
--
Scott I. Blanksteen
sib (at) worldnet (dot) att (dot) net
------------------------------
Date: Sat, 17 May 1997 14:29:27 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: James Adams <jadams@skimmer.fsl.noaa.gov>
Subject: Re: what's this ? "stack dump during die..."
Message-Id: <Pine.GSO.3.96.970517142546.995N-100000@kelly.teleport.com>
On Wed, 14 May 1997, James Adams wrote:
> I have a message that has started to come up whenever I run my
> script in debugger mode (-d switch):
>
> Stack dump during die enabled outside of evals.
>
> Can anyone enlighten me as to what this may be, if it is
> anything to worry about, or how I might fix it ?
Somebody who knows more (Hi, Ilya! :-) should give the full details, but I
think it's nothing to worry about, and actually a Good Thing. I believe
that it means that if your program die()s, the debugger will take over and
tell you what happened, rather than terminating Perl instantly. The
exception is if the die is within an eval, which is (of course) trapped by
the eval instead of by the debugger.
Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: 17 May 1997 21:40:40 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: what's this ? "stack dump during die..."
Message-Id: <5ll8ko$e8f$2@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Tom Phoenix
<rootbeer@teleport.com>],
who wrote in article <Pine.GSO.3.96.970517142546.995N-100000@kelly.teleport.com>:
> On Wed, 14 May 1997, James Adams wrote:
>
> > I have a message that has started to come up whenever I run my
> > script in debugger mode (-d switch):
> >
> > Stack dump during die enabled outside of evals.
> >
> > Can anyone enlighten me as to what this may be, if it is
> > anything to worry about, or how I might fix it ?
>
> Somebody who knows more (Hi, Ilya! :-) should give the full details, but I
> think it's nothing to worry about, and actually a Good Thing. I believe
> that it means that if your program die()s, the debugger will take over and
> tell you what happened, rather than terminating Perl instantly. The
> exception is if the die is within an eval, which is (of course) trapped by
^^^^^^^^^^^
> the eval instead of by the debugger.
This message is disabled in newest debuggers (it was getting to a
wrong filehandle anyway).
Your description is absolutely correct, except one thing. The `(of
course)' above is not. You need to apply some additional work to NOT
trap dies inside evals.
Btw, debugger will not trap die()s inside eval()s (unless asked to do
this), but only for explicit evals. With implicit ones (like DESTROY)
it will print a backtrace.
Ilya
------------------------------
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 493
*************************************