[19365] in Perl-Users-Digest
Perl-Users Digest, Issue: 1560 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 18 18:05:33 2001
Date: Sat, 18 Aug 2001 15:05:11 -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: <998172311-v10-i1560@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 18 Aug 2001 Volume: 10 Number: 1560
Today's topics:
Re: Coercing list context onto pair of regexps in a com <uri@sysarch.com>
Re: Coercing list context onto pair of regexps in a com (Steven Smolinski)
Copy file in Perl <ernst.wernli@gibthun.ch>
Re: Copy file in Perl <Tassilo.Parseval@post.rwth-aachen.de>
Re: Copy file in Perl <ilya@martynov.org>
Re: Copy file in Perl <godzilla@stomp.stomp.tokyo>
Re: Copy file in Perl <philip@zaynar.demon.co.uk>
Delivering to Apple Mailbox using Mail::Audit <henris@clinet.fi>
Dynamic IP, Router and Nameserverupdate with PERL-Scrip <Uwe@familie-betz.de>
FAQ: Why do I get weird spaces when I print an array of <faq@denver.pm.org>
Re: Finding keywords in text files (shaz)
Re: Finding keywords in text files (Tad McClellan)
Re: Issues with "deleting" files using variables <textfx@vol.com>
Re: Issues with "deleting" files using variables (Tad McClellan)
Issues with opening files using variables <textfx@vol.com>
Re: Issues with opening files using variables <shutupsteve@awdang.no.thanks.com>
Re: Issues with opening files using variables <krahnj@acm.org>
Re: Issues with opening files using variables (Tad McClellan)
Re: local exec via cgi (Malcolm Dew-Jones)
Re: Local Perl via browser <wsegrave@mindspring.com>
Re: Modifying single-characters <removespamjeremyalansmith@netscapeonline.co.uk>
Re: perl packages & ASP (Tim Hammerquist)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 18 Aug 2001 19:06:41 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Coercing list context onto pair of regexps in a comparison
Message-Id: <x7u1z5i3wc.fsf@home.sysarch.com>
>>>>> "EB" == Eric Bohlman <ebohlman@omsdev.com> writes:
EB> Someone forging the name of Uri Guttman <uri@sysarch.com> wrote:
>> When Charlie's violent fax machine moans, ...
EB> I think there's potential for a song title here.
and that was forged. i never wrote that. note among other things it
doesn't have my signature.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: Sat, 18 Aug 2001 20:03:16 GMT
From: steven.smolinski@sympatico.ca (Steven Smolinski)
Subject: Re: Coercing list context onto pair of regexps in a comparison
Message-Id: <8Szf7.60939$zg6.5415745@news20.bellglobal.com>
Uri Guttman <uri@sysarch.com> wrote:
> Someone forging the name of Uri Guttman <uri@sysarch.com> wrote:
> >> When Charlie's violent fax machine moans, ...
> [...]
> and that was forged. i never wrote that. note among other things it
> doesn't have my signature.
The real giveaway was the proper use of capitalization. You've never
been accused of that.
Steve
--
Steven Smolinski => http://arbiter.ca/
------------------------------
Date: Sat, 18 Aug 2001 17:33:37 +0200
From: Ernst Wernli <ernst.wernli@gibthun.ch>
Subject: Copy file in Perl
Message-Id: <3B7E8AD1.A4B8B11D@gibthun.ch>
--------------50DD7037FDA0438121607B2B
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi,
I've to copy files with PERL. How can I do it?
Exemple:
N:\temp\test.htm
N:\temp\last\test.htm
Thank you
Ernst
--------------50DD7037FDA0438121607B2B
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Hi,
<p>I've to copy files with PERL. How can I do it?
<p>Exemple:
<blockquote>N:\temp\test.htm
<br>N:\temp\last\test.htm</blockquote>
Thank you
<br>Ernst</html>
--------------50DD7037FDA0438121607B2B--
------------------------------
Date: Sat, 18 Aug 2001 17:41:52 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Copy file in Perl
Message-Id: <3B7E8CC0.4020001@post.rwth-aachen.de>
Ernst Wernli wrote:
> Hi,
>
> I've to copy files with PERL. How can I do it?
Sounds like a File::Copy job. See 'perldoc File::Copy'.
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: 18 Aug 2001 19:43:21 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Copy file in Perl
Message-Id: <873d6pml0m.fsf@abra.ru>
EW> Hi,
EW> I've to copy files with PERL. How can I do it?
EW> Exemple:
EW> N:\temp\test.htm
EW> N:\temp\last\test.htm
use File::Copy;
copy("N:\\temp\\test.htm", "N:\\temp\\last\\test.htm");
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: Sat, 18 Aug 2001 11:17:25 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Copy file in Perl
Message-Id: <3B7EB135.3545C3C6@stomp.stomp.tokyo>
Ernst Wernli wrote:
(snipped)
> I've to copy files with PERL. How can I do it?
This simplistic nature of your question indicates you
need to study and learn Perl better before attempting
to write scripts.
You may use a stereotypical Perl 5 Cargo Cult method
which requires only skill with a mouse, resulting in
a slow and inefficient script:
use File::Copy;
copy ("test1.txt", "test2.txt");
Should your system not support Perl generated system
calls, you may use a classic Perl 4 style method which
is significantly faster and more efficient than this
typical Copy & Paste Baby Perl 5 Cargo Cult method above:
open (FILEHANDLE1, "test1.txt");
open (FILEHANDLE2, ">test2.txt");
while (<FILEHANDLE1>)
{ print FILEHANDLE2 $_; }
close (FILEHANDLE1);
close (FILEHANDLE2);',
With a system which supports Perl generated system calls,
you may use a lightening fast method.
DOS method:
`copy test1.txt test2.txt`;
UNIX method:
system ("cp test1.txt test2.txt");
You have choices now. You may elect to become a typical
Perl 5 Cargo Cultist and write slow inefficient scripts,
or you may elect to become a talented Perl programmer
and write fast efficient scripts employing a variety
of methods learned by actually writing Perl programs.
Nonetheless, your question is a red flag you do not yet
know enough about Perl to be writing scripts more complex
than,
print "Hello World!";
Research and read about Perl extensively before proceeding
any further with your script writing.
Godzilla!
--
#!perl
print "Content-type: text/plain\n\n";
use Benchmark;
print "Run One:\n\n";
&Time;
print "\n\nRun Two:\n\n";
&Time;
print "\n\nRun Three:\n\n";
&Time;
sub Time
{
timethese (10000,
{
'name1' =>
'use File::Copy;
copy("test1.txt", "test2.txt");',
'name2' =>
'open (FILEHANDLE1, "test1.txt");
open (FILEHANDLE2, ">test2.txt");
while (<FILEHANDLE1>)
{ print FILEHANDLE2 $_; }
close (FILEHANDLE1);
close (FILEHANDLE2);',
'name3' =>
'`copy test1.txt test2.txt`;',
} );
}
PRINTED RESULTS:
________________
Run One:
Benchmark: timing 10000 iterations of name1, name2, name3...
name1: 11 wallclock secs (11.48 usr + 0.00 sys = 11.48 CPU) @ 871.08/s
name2: 8 wallclock secs ( 7.47 usr + 0.00 sys = 7.47 CPU) @ 1338.69/s
name3: 1 wallclock secs ( 1.26 usr + 0.00 sys = 1.26 CPU) @ 7936.51/s
Run Two:
Benchmark: timing 10000 iterations of name1, name2, name3...
name1: 12 wallclock secs (11.48 usr + 0.00 sys = 11.48 CPU) @ 871.08/s
name2: 7 wallclock secs ( 7.52 usr + 0.00 sys = 7.52 CPU) @ 1329.79/s
name3: 2 wallclock secs ( 1.26 usr + 0.00 sys = 1.26 CPU) @ 7936.51/s
Run Three:
Benchmark: timing 10000 iterations of name1, name2, name3...
name1: 11 wallclock secs (11.48 usr + 0.00 sys = 11.48 CPU) @ 871.08/s
name2: 8 wallclock secs ( 7.53 usr + 0.00 sys = 7.53 CPU) @ 1328.02/s
name3: 1 wallclock secs ( 1.26 usr + 0.00 sys = 1.26 CPU) @ 7936.51/s
------------------------------
Date: Sat, 18 Aug 2001 21:58:10 +0100
From: Philip Taylor <philip@zaynar.demon.co.uk>
Subject: Re: Copy file in Perl
Message-Id: <pPzk5AAibtf7EwYM@zaynar.demon.co.uk>
In article <3B7EB135.3545C3C6@stomp.stomp.tokyo>, Godzilla!
<godzilla@stomp.stomp.tokyo> writes
>Should your system not support Perl generated system
>calls, you may use a classic Perl 4 style method which
>is significantly faster and more efficient than this
>typical Copy & Paste Baby Perl 5 Cargo Cult method above:
>
>
> open (FILEHANDLE1, "test1.txt");
> open (FILEHANDLE2, ">test2.txt");
> while (<FILEHANDLE1>)
> { print FILEHANDLE2 $_; }
> close (FILEHANDLE1);
> close (FILEHANDLE2);',
In DOS, you ought to run binmode on both the files in case they're
binary files, unless you're certain that they're not going to be.
On a 3-byte file, I get similar results to yours (i.e. open/print
quicker than File::Copy). But on a 1 megabyte file (20,000 lines of 48
"a"s followed by "\r\n") I get:
File::Copy: 2 wallclock secs ( 1.26 usr + 0.00 sys = 1.26 CPU) @
15.87/s (n=20)
Open/Print: 16 wallclock secs (16.48 usr + 0.00 sys = 16.48 CPU) @
1.21/s (n=20)
(the `copy ...` method tries to access my floppy drive every time it
runs the command, so I cannot include it in the test)
Testing with different sized files shows that the open/print method is
faster only for files less than about 1,500 bytes in size.
Any HTML files with useful content will be far larger than that, making
File::Copy the best option.
--
Philip Taylor
philip @ zaynar . demon . co . uk
http://robowarriors.ultrastore.com/legoworld.shtml
-- If the Earth was made of Lego...
------------------------------
Date: Sat, 18 Aug 2001 23:04:50 +0300
From: Henri Sivonen <henris@clinet.fi>
Subject: Delivering to Apple Mailbox using Mail::Audit
Message-Id: <henris-48EA5B.23045018082001@uutiset.saunalahti.fi>
I've written a mail filter using Mail::Audit. I'm trying to deliver
messages to local "Unix account" mailboxes on Mac OS X and read the
mailboxes using Apple's Mail.app.
If I ask Mail::Audit to deliver a message that I have copied from a
Mail.app mailbox, it works fine. However, when I ask Mail::Audit to
deliver a message copied from my old Eudora mailbox, the message ends up
in the mailbox file, but Mail.app doesn't see the message.
Has anyone else tried this? Is this a solution for making Mail::Audit
work with Mail.app? Any guesses on what might be wrong?
--
Henri Sivonen
henris@clinet.fi
http://www.clinet.fi/~henris/
------------------------------
Date: Sat, 18 Aug 2001 17:56:55 +0200
From: "Uwe Betz" <Uwe@familie-betz.de>
Subject: Dynamic IP, Router and Nameserverupdate with PERL-Script
Message-Id: <9lma98.1as.1@deggendorf.conactive.de>
Hi folks,
I am in trouble and a non programmer :-(
But I think a solution in perl should be no problem and maybe already
exists.
I have a router connected network (SMC-Router) with Dynamic IP on the
WAN-Side. What I need is a tool running on a linux-machine which detects
whenever the router-ip (external ip) changes. This can be done by connecting
to the Webinterface of the router an d read the IP-Field. Then the script
should log this change with date and time and new ip and generate an email
which is preformatted, set the current ip on a defined position and send the
email to my nameserver-robot. then my nameserver will be able to resolve my
local network even after the ip changes. As i have my own nameserver it
makes no sense for my to use an dynDNS-Provider.
Maybe someone knows such a script or maybe a script which does a part of
what I need (read a html-field from the routers webserver, generate an email
and send it, etc.). Then I can try without any knwoledge to learn by doing
:-)
Maybe someone has time to write this within a few minitues, thaen I'll give
you the necessary information for testing and writing.
Thanks for any help,
regards,
uwe
------------------------------
Date: Sat, 18 Aug 2001 18:17:00 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: Why do I get weird spaces when I print an array of lines?
Message-Id: <wiyf7.232$V3.195621376@news.frii.net>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.
+
Why do I get weird spaces when I print an array of lines?
Saying
print "@lines\n";
joins together the elements of "@lines" with a space between them. If
"@lines" were "("little", "fluffy", "clouds")" then the above statement
would print
little fluffy clouds
but if each element of "@lines" was a line of text, ending a newline
character "("little\n", "fluffy\n", "clouds\n")" then it would print:
little
fluffy
clouds
If your array contains lines, just print them:
print @lines;
-
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to
news:news.answers
or to the many thousands of other useful Usenet news groups.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-1999 Tom Christiansen and Nathan
Torkington. All rights reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
06.00
--
This space intentionally left blank
------------------------------
Date: 18 Aug 2001 12:50:28 -0700
From: ssa1701@yahoo.co.uk (shaz)
Subject: Re: Finding keywords in text files
Message-Id: <23e71812.0108181150.1e7de79f@posting.google.com>
I have a program which finds the keyword in a text file. It searches
for words that have a particular tag and then removes the words which
are also present in a stoplist.
I want to modify the program so that it finds terms instead. Instead
of finding a single word it should find multiple words. These words
should have a particular set of tags.
The following tag combinations are allowed:-
WORD/NN WORD/NN
WORD/JJ WORD/NNS
The code is as follows:-
#!/usr/bin/perl -w
my @tags = ('/NN', '/NNS', '/JJ');
my $search = join('|',@tags);
my %taglist;
open(DATA, "read.txt") || die "Cannot open file: $!";
while (<DATA>)
{
while (/(\w+)($search)/og)
{
print "$1 -> $2\n";
$taglist{$2}{$1}++;
}
}
foreach my $tag (sort keys %taglist)
{
print "\nTag $tag\n";
foreach my $word (sort keys %{$taglist{$tag}})
{
print "\t$word ($taglist{$tag}{$word})\n";
}
}
close(DATA);
An example file (read.txt) to read is:-
This/AB is/CD part/AC of/RE the/ID text/NN file/NN read/UJ and/TR
also/TR the/ID final/JJ report/NNS. This/AB is/VF used/DF by/FD tab/NN
the/ID book/NN. The/ID read/NN file/NN is/AB here/AS.
The program should find the following and also their count:-
file read (2)
final report (1)
------------------------------
Date: Sat, 18 Aug 2001 16:31:07 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Finding keywords in text files
Message-Id: <slrn9ntk4b.fl7.tadmc@tadmc26.august.net>
shaz <ssa1701@yahoo.co.uk> wrote:
>I have a program which finds the keyword in a text file. It searches
>for words that have a particular tag and then removes the words which
>are also present in a stoplist.
>#!/usr/bin/perl -w
use strict;
>my @tags = ('/NN', '/NNS', '/JJ');
>my $search = join('|',@tags);
Have you happened to notice that it *never* matches /NNS ?
Better fix that first:
my @tags = ('/NNS', '/NN', '/JJ');
or
my $search = join('|', sort { $b cmp $a } @tags);
Perl goes left-to-right through the alternatives and stops at
the first one that matches. You should ensure the longer ones
come first if some patterns are prefixes of other patterns.
I don't understand what you want, so I cannot help with your real
problem. Just noticed a bug in your existing program...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 18 Aug 2001 14:18:10 -0500
From: Stan Kilgore <textfx@vol.com>
Subject: Re: Issues with "deleting" files using variables
Message-Id: <B5A13B468382C7EE.F4A2AF74EF616657.EC4F69F722CD6B0D@lp.airnews.net>
Should have been "deleting" instead of "opening"... on the 32nd hour
without sleep... :)
Stan
"Java? I've heard of that.... I drink it while coding Perl"
On Sat, 18 Aug 2001 13:57:24 -0500, Stan Kilgore <textfx@vol.com>
wrote:
>Greets all,
>
>This is the first post here, so be gentle.. :)
>
>I have a script which is going to be deleting files based on a
>username. When the account is created, the path is like:
>
>
>----------------------CODE-------------------------
>
>$username = "bob"; #actually, this info is taken from an
>administration form, not hard coded.
>
>$user_public_folder = "/path/to/file/" . $username;
>
>$file1 = $user_public_folder . "/firstfile.txt";
>$file2 = $user_public_folder . "/secondfile.txt";
>...
>...
>
>print `mkdir $user_public_folder`;
>open(FILE, ">$file1") || die "Cannot create file1!";
>print FILE "Some text\n";
>close(FILE);
>
>
>------------------------CODE-----------------------------------
>
>This works fine and dandy... however, the problem comes in when I want
>to delete the same file. If it is handled like this:
>
>-----------------MORE CODE-------------------------
>
>$filetokill = "/path/to/file/bob/firstfile.txt";
>
>unlink($filetokill);
>
>-----------------MORE CODE---------------------------
>
>...it works like a charm... however, when handled like this:
>
>--------------------YET MORE CODE-------------------------
>
>$filetokill = "/path/to/file/" . $username . "/firstfile.txt";
>
>print $filetokill;
>
>unlink($filetokill);
>
>--------------------YET MORE CODE-------------------------
>
>...the print statement will output "/path/to/file/bob/firstfile.txt",
>but the program will die when it tries to unlink $filetokill. I cannot
>understand why.
>
>For informational purposes, I am running the script under Perl 5, but
>from the test server, I cannot access the error logs, nor can I telnet
>directly to the test server (someone hacked the shell and ruined it
>for the rest of us). Also, I do not use CGI.pm, as I have always
>preferred not to. No particular reason, other than laziness. :)
>
>Thanks in advance for any help.
>
>Stan Kilgore
>SequatchieOnline.Com
>
------------------------------
Date: Sat, 18 Aug 2001 16:44:49 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Issues with "deleting" files using variables
Message-Id: <slrn9ntku1.fl7.tadmc@tadmc26.august.net>
Stan Kilgore <textfx@vol.com> wrote:
>Should have been "deleting" instead of "opening"... on the 32nd hour
>without sleep... :)
What should have been deleting instead of opening?
You quoted about 75 lines (in backwards time order, including
the .sig even).
We should go searching through all of that to figure out
what you mean?
Please learn the proper method for posting to Usenet:
http://www.geocities.com/nnqweb/nquote.html
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 18 Aug 2001 13:57:24 -0500
From: Stan Kilgore <textfx@vol.com>
Subject: Issues with opening files using variables
Message-Id: <D9F52333FEA9A61B.E081E5E491C3C708.934CD947FB894D26@lp.airnews.net>
Greets all,
This is the first post here, so be gentle.. :)
I have a script which is going to be deleting files based on a
username. When the account is created, the path is like:
----------------------CODE-------------------------
$username = "bob"; #actually, this info is taken from an
administration form, not hard coded.
$user_public_folder = "/path/to/file/" . $username;
$file1 = $user_public_folder . "/firstfile.txt";
$file2 = $user_public_folder . "/secondfile.txt";
...
...
print `mkdir $user_public_folder`;
open(FILE, ">$file1") || die "Cannot create file1!";
print FILE "Some text\n";
close(FILE);
------------------------CODE-----------------------------------
This works fine and dandy... however, the problem comes in when I want
to delete the same file. If it is handled like this:
-----------------MORE CODE-------------------------
$filetokill = "/path/to/file/bob/firstfile.txt";
unlink($filetokill);
-----------------MORE CODE---------------------------
...it works like a charm... however, when handled like this:
--------------------YET MORE CODE-------------------------
$filetokill = "/path/to/file/" . $username . "/firstfile.txt";
print $filetokill;
unlink($filetokill);
--------------------YET MORE CODE-------------------------
...the print statement will output "/path/to/file/bob/firstfile.txt",
but the program will die when it tries to unlink $filetokill. I cannot
understand why.
For informational purposes, I am running the script under Perl 5, but
from the test server, I cannot access the error logs, nor can I telnet
directly to the test server (someone hacked the shell and ruined it
for the rest of us). Also, I do not use CGI.pm, as I have always
preferred not to. No particular reason, other than laziness. :)
Thanks in advance for any help.
Stan Kilgore
SequatchieOnline.Com
------------------------------
Date: Sat, 18 Aug 2001 12:16:12 -0700
From: "Stephen Deken" <shutupsteve@awdang.no.thanks.com>
Subject: Re: Issues with opening files using variables
Message-Id: <tntfmios1g6n07@corp.supernews.com>
"Stan Kilgore" <textfx@vol.com> wrote:
> ...the print statement will output "/path/to/file/bob/
> firstfile.txt", but the program will die when it tries
> to unlink $filetokill. I cannot understand why.
I get this while running a slightly modified version of your script:
Insecure dependency in unlink while running with -T switch at ./test.pl
line 9.
You *are* running with taint checking on, right? Try this, just after you
obtain the username:
die "Tainted username $username" unless ($username =~ /^(\w+)$/);
$username = $1;
> Also, I do not use CGI.pm, as I have always preferred
> not to. No particular reason, other than laziness. :)
If you were lazy, you *would* be using CGI.pm. :)
--sjd;
------------------------------
Date: Sat, 18 Aug 2001 19:27:28 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Issues with opening files using variables
Message-Id: <3B7EC1F0.4CD02B5E@acm.org>
Stan Kilgore wrote:
>
> This is the first post here, so be gentle.. :)
>
> I have a script which is going to be deleting files based on a
> username. When the account is created, the path is like:
>
> [snip code]
>
> ...it works like a charm... however, when handled like this:
>
> --------------------YET MORE CODE-------------------------
>
> $filetokill = "/path/to/file/" . $username . "/firstfile.txt";
>
> print $filetokill;
>
> unlink($filetokill);
>
> --------------------YET MORE CODE-------------------------
>
> ...the print statement will output "/path/to/file/bob/firstfile.txt",
> but the program will die when it tries to unlink $filetokill. I cannot
> understand why.
>
> For informational purposes, I am running the script under Perl 5, but
> from the test server, I cannot access the error logs, nor can I telnet
> directly to the test server (someone hacked the shell and ruined it
> for the rest of us). Also, I do not use CGI.pm, as I have always
> preferred not to. No particular reason, other than laziness. :)
The unlink() function as well as most (all?) of perl's system functions
will return true on success and false on failure and set the $! variable
to indicate what caused the failure. Learn to use the tools that perl
provides.
unlink $filetokill or die "Cannot unlink $filetokill: $!";
open FILE, ">$file1" or die "Cannot create $file1: $!";
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 18 Aug 2001 16:41:30 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Issues with opening files using variables
Message-Id: <slrn9ntknq.fl7.tadmc@tadmc26.august.net>
Stan Kilgore <textfx@vol.com> wrote:
>
>This is the first post here, so be gentle.. :)
What doesn't kill you makes you stronger.
>I have a script which is going to be deleting files based on a
>username. When the account is created, the path is like:
>$username = "bob"; #actually, this info is taken from an
>administration form, not hard coded.
^^^^
Do you mean <form> there? As in a WWW form?
You had better have taint checking turned on then.
Do you?
>$user_public_folder = "/path/to/file/" . $username;
I think this form is easier to read and understand:
$user_public_folder = "/path/to/file/$username";
>the problem comes in when I want
>to delete the same file. If it is handled like this:
>
>-----------------MORE CODE-------------------------
>
>$filetokill = "/path/to/file/bob/firstfile.txt";
>
>unlink($filetokill);
Nothing comes from outside of your program here...
>...it works like a charm... however, when handled like this:
>$filetokill = "/path/to/file/" . $username . "/firstfile.txt";
>print $filetokill;
>unlink($filetokill);
Here $username will be tainted if you have taint checking turned on
as you should have.
>...the print statement will output "/path/to/file/bob/firstfile.txt",
>but the program will die when it tries to unlink $filetokill. I cannot
>understand why.
Have you untainted $username?
That would cause it to fail.
>For informational purposes, I am running the script under Perl 5, but
>from the test server, I cannot access the error logs,
You can see error messages even without access to the server logs.
Perl FAQ, part 9:
"How can I get better error messages from a CGI program?"
>Also, I do not use CGI.pm, as I have always
>preferred not to.
You have never said that you were running this Perl program in
the CGI environment. That is Very Important Information if you
wish to get good help.
Most Perl programs do not run under the CGI environment. You
should point it out when you are not in the "usual" environment.
>No particular reason, other than laziness. :)
That is false laziness. You will pay for it some day.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 18 Aug 2001 10:51:52 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: local exec via cgi
Message-Id: <3b7eab38@news.victoria.tc.ca>
GunneR (ds@ss.com) wrote:
: I know this is very insecure, and im not sure if its even perl
: related, but...
: Im trying to write a cgi script that executes local code (via system,
: exec, etc) on the system that visits the page.
: My alternative is to use socket (server, client) stuff to talk back
: and fourth (Linux, Windows) but that could get messy. Is there some
: funky module that does this or do I have to write some real shoddy cgi
: code? TIA!
Search for and download one of the virus creation kits that apparently
abound if you know where to look.
They will help you to make pages that run arbitrary code when run from MS
IE (and possibly Navigator 6, I understand it has problems too now).
If you have a legit reason for runing code then make some kind of plugin
for the browser that the user could download ahead of time. If you take
this route then make sure the plugin has some kind of checking so it only
honours requests from your trusted servers.
In any case, I do not see that this has anything to do with Perl.
------------------------------
Date: Sat, 18 Aug 2001 11:24:26 -0500
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Local Perl via browser
Message-Id: <9lm5fs$kdj$1@slb6.atl.mindspring.net>
"Samneric" <samneric@tigerriverOMIT-THIS.com> wrote in message
news:MPG.15e836dfeb8d397d989687@news.usit.net...
**snipped***
> If you don't want to install and configure a webserver, check out Micro
Web, by
> Indigo Star ( www.indigostar.com/microweb.htm ). Very simple to use with
> Activestate's perl, requiring that you only unzip it to a directory.
>
Thanks for the suggestion. The OP may wish to consider the following:
I had recommended TinyWeb on similar merits. IIRC, TinyWeb is free, while
MicroWeb is shareware.
OTOH, from the MicroWeb on-line manual, MicroWeb appears to have SSI, which
could be a significant advantage in favor its use.
Bill Segraves
Auburn, AL
------------------------------
Date: Fri, 17 Aug 2001 11:29:20 +0100
From: "Jeremy Smith" <removespamjeremyalansmith@netscapeonline.co.uk>
Subject: Re: Modifying single-characters
Message-Id: <vWvf7.1227$in6.375517@news6-win.server.ntlworld.com>
"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:uepontk4ler3lsh89k26jldven820sp22l@4ax.com...
> Jeremy Smith wrote:
>
> >So to turn an 'A' into a 'B' I have done:
> >
> >$oldchar=ord('A');
> >$addchar=$oldchar+1;
> >$newchar=chr($addchar);
>
> $char = 'A';
> vec($char, 0, 8)++;
> print $char;
> -->
> B
>
> vec() is one way to treat a string as an array of (8 bit) integers. So I
> increment the first such integer (=a byte) in that string.
>
> Yes, $char++ would work too, in this case. But start with $char='Z' and
> you'll notice the difference.
Okay, thanks.
The 'vec' function is just what I needed. I just checked the syntax of it in
Perldoc.
So I just do vec($char,0,8)-=48 to turn a "h" into an "8".
Thanks everyone,
Jeremy.
------------------------------
Date: Sat, 18 Aug 2001 20:16:27 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: perl packages & ASP
Message-Id: <slrn9ntju6.su.tim@vegeta.ath.cx>
Me parece que TedWeb <ted_godwin@mindspring.com> dijo:
> My perl packages don't have access to ASP intrinsic objects (i.e. Session,
> Server, etc.). They are implemented through means of server side includes.
> Is there anyway I can correct this, or do I have to send the intrinsic
> objects through the specified routine argument list?
I'm not sure I understand your question entirely, but I'll give it a go.
A Perl package by itself won't have access to the ASP objects. Only a
PerlScript ASP page. In ASP PerlScript, the objects are accessible
thus:
$Application
$Session
$Response
etc.
And methods are called thus:
$Response->Write( "Stuff" );
Only ASP PerlScript pages (pages matching *.asp and, usually, with
'<%@language=PerlScript%> in the contents) and modules called from these
ASP pages have access to ASP objects. There may be a work around using
Win32::OLE, but I neither know it, nor can I see a reason for it. Inside
these pages, the ASP objects are available as global vars, so you need a
trick to get them to work under 'use strict;' This works:
<%@language=PerlScript%>
<%
use strict;
use vars ($Application, $Request, $Reponse, $Session, ...);
$Response->Write("<H1>The Sleeper Has Awakened</H1>");
%>
<H2>I am the Prince of All Saiyans Once Again!</H2>
Does this answer our question? If not, include more details and we'll
give it another shot. ;)
> Many thanks,
> Ted
--
Things need not have happened to be true. Tales and dreams are the shadow
truths that will endure when mere facts are dust and ashes, and forgot.
-- Morpheus, The Sandman
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 1560
***************************************