[11384] in Perl-Users-Digest
Perl-Users Digest, Issue: 4987 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 26 16:07:31 1999
Date: Fri, 26 Feb 99 13:04:04 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 26 Feb 1999 Volume: 8 Number: 4987
Today's topics:
Need help with filenames (ref)
Re: Need help with filenames (Jordan I. K. McClure)
Re: Need help with filenames <jglascoe@giss.nasa.gov>
Re: Need help with filenames (Tad McClellan)
Need help with Perl to tcl conversion <cpavel@nortelnetworks.com>
need help with Perl-dB connection mlconley@my-dejanews.com
Re: need help with Perl-dB connection <jdf@pobox.com>
Re: need help with Perl-dB connection <andrewf@beausys.demon.co.uk>
need help with PRINT <LeTigre@Multimania.no-spam.com>
Re: need help with PRINT droby@copyright.com
Re: need help with PRINT <LeTigre@Multimania.no-spam.com>
Re: need help with PRINT <stevenhenderson@prodigy.net>
Need Help With Simple Code <ophir@saifun.com>
Re: Need Help With Simple Code <jglascoe@giss.nasa.gov>
Re: Need Help With Simple Code (Larry Rosler)
Re: Need Help With Simple Code <Philip.Newton@datenrevision.de>
Need Help. Password checking CGI script. <seugenio@man.amis.com>
Re: Need Help. Password checking CGI script. <kenhirsch@myself.com>
Re: Need Random Link Script! HELP! <jeffp@crusoe.net>
Re: Need Random Link Script! HELP! <gdschrij@eduserv2.rug.ac.be>
Need script for HTTP filtering <ansis@my-dejanews.com>
Re: Need script for HTTP filtering <gdschrij@eduserv2.rug.ac.be>
Re: Need script for HTTP filtering <ataols@lanet.lv>
Re: Need script for HTTP filtering <bill@fccj.org>
Re: Need script for HTTP filtering <jeff@vpservices.com>
Re: Need script for HTTP filtering (Randal L. Schwartz)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 23 Feb 1999 11:28:59 -0600
From: ref@realtime.net (ref)
Subject: Need help with filenames
Message-Id: <7auogr$c1l@jake.bga.com>
Can someone come up with a script to rename multiple files containing a given string?
Specifically, say you have files with an "old" suffix, like this:
abc.old
bcd.old
cde.old
...and you want to find them and rename them with a new suffix:
abc.new
bcd.new
cde.new
Additionally, is it possible to have a script that would do this not only
in the present directory, but in all subdirectories within it?
Many thanks,
Ron M.
------------------------------
Date: 23 Feb 1999 18:30:45 GMT
From: jimcclur@ews.uiuc.edu (Jordan I. K. McClure)
Subject: Re: Need help with filenames
Message-Id: <7aus4l$fjb$1@vixen.cso.uiuc.edu>
Here's one way to do it:
for $file (<*.old>) {
$file =~ /(.*?)\.err/i;
rename ($file, "$1.new"))
}
To have it recurese through directories, look at the -d filetest
operator and the opendir and readdir functions.
jordan
ref (ref@realtime.net) wrote:
:
: Can someone come up with a script to rename multiple files containing a given string?
:
: Specifically, say you have files with an "old" suffix, like this:
:
: abc.old
: bcd.old
: cde.old
:
: ...and you want to find them and rename them with a new suffix:
:
: abc.new
: bcd.new
: cde.new
:
:
: Additionally, is it possible to have a script that would do this not only
: in the present directory, but in all subdirectories within it?
:
: Many thanks,
: Ron M.
--
If at first you don't succeed, skydiving is not for you.
------------------------------
Date: Tue, 23 Feb 1999 13:44:07 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: ref <ref@realtime.net>
Subject: Re: Need help with filenames
Message-Id: <36D2F6F7.F50BE750@giss.nasa.gov>
[courtesy copy of post sent to Ron]
ref wrote:
>
> Can someone come up with a script to rename multiple files containing a given string?
>
> Specifically, say you have files with an "old" suffix, like this:
>
> abc.old
> bcd.old
> cde.old
>
> ...and you want to find them and rename them with a new suffix:
>
> abc.new
> bcd.new
> cde.new
for (grep { -f } <./*.old>)
{
my $old = $_;
s/\.old$/.new/;
rename $old, $_;
}
> Additionally, is it possible to have a script that would do this not only
> in the present directory, but in all subdirectories within it?
I would call "ls -R" through the shell to get a list
of all files recursively contained in the pwd.
--
"It's okay to grow up--just as long as you
don't grow old. Face it... you are young."
--Pulp
------------------------------
Date: Tue, 23 Feb 1999 10:13:24 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Need help with filenames
Message-Id: <kigua7.sh5.ln@magna.metronet.com>
Jay Glascoe (jglascoe@giss.nasa.gov) wrote:
: ref wrote:
: > Additionally, is it possible to have a script that would do this not only
: > in the present directory, but in all subdirectories within it?
: I would call "ls -R" through the shell to get a list
: of all files recursively contained in the pwd.
Then you would be ignoring that there is an already-invented
all-Perl wheel that does the same thing.
Namely the File::Find module.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 23 Feb 1999 08:52:11 -0500
From: "Pavel, Cristian" <cpavel@nortelnetworks.com>
Subject: Need help with Perl to tcl conversion
Message-Id: <36D2B28B.DA28AA92@nortelnetworks.com>
I know this question it is not quite right for this group
but I need help and I count on you guys.
I have/must to convert an entire sub-system to tcl (please
don't ask why, it is hurting enough). The firts&last time I
touched tcl was 4 years ago and I didn't like it. But I wish
and hope that tcl is quite different nowadays.
My sub-system uses intensively Net::Telnet (thanks again
Jay Rogers for a good & very useful module).
Has tcl a similar package? I don't want to use ptys so expect
is out of question. I already looked at the following packages:
tclRawTCP, tclTCP2.2, tcpConnect and tcp-DP and they are
not what I need.
TIA,
Cristian
--
cpavel@nortelnetworks.com
UNIX - is user friendly. It's just selective who the friends are.
Linux - is like a wigwam: no windows, no gates, apache inside.
------------------------------
Date: Wed, 24 Feb 1999 17:32:40 GMT
From: mlconley@my-dejanews.com
Subject: need help with Perl-dB connection
Message-Id: <7b1d3o$ur2$1@nnrp1.dejanews.com>
hi everyone,
I just started programming in Perl and I'm only 11, so please don't kill me
if I ask a stupid question.
I have a little access database and I want to paint a web page that
dynamically gets changed when someone adds something to it. So I'm looking
at Page A and all the while, Perl is looking at the database for a new record
to appear and once it does to send it to the web page.
On the CGI side, I THINK I need to use server push to keep the connection
open, but I really don't know how to keep repolling the Access database
waiting for a record to appear. Can someone help me?
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 24 Feb 1999 23:10:49 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: mlconley@my-dejanews.com
Subject: Re: need help with Perl-dB connection
Message-Id: <m3678rw2ba.fsf@joshua.panix.com>
mlconley@my-dejanews.com writes:
> I just started programming in Perl and I'm only 11, so please don't
> kill me if I ask a stupid question.
Your question is interesting.
The only "stupid questions" in this newsgroup are those that are
already answered in the documentation. Please note that being 11
years old does *not* mean you get to skip the documentation.
Nobody has yet figured out how to actually kill anybody via Usenet.
If somebody *had* figured out a way to do so, I'd probably be dead.
> I really don't know how to keep repolling the Access database
> waiting for a record to appear.
Do you know how to get to your data from Perl in the first place? I
recommend that you set up an ODBC data source and use DBI::ODBC.
Do you know how to wait a few seconds (so that you're not constantly
draining your machine's precious CPU time)?
perldoc -f sleep
Your program would have a section like this...
while (still talking to the user) {
if (there are more records in the table) {
inform the user
}
sleep(some number of seconds)
}
Web technology issues are beyond the scope of this group, but you seem
to know that already. I hope this helps.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Fri, 26 Feb 1999 00:15:34 +0000
From: Andrew Fry <andrewf@beausys.demon.co.uk>
Subject: Re: need help with Perl-dB connection
Message-Id: <3YzyTQAmee12Ewuz@beausys.demon.co.uk>
In article <m3678rw2ba.fsf@joshua.panix.com>, Jonathan Feinberg
<jdf@pobox.com> writes
>mlconley@my-dejanews.com writes:
>
>> I just started programming in Perl and I'm only 11, so please don't
>> kill me if I ask a stupid question.
>
>Your question is interesting.
>
>The only "stupid questions" in this newsgroup are those that are
>already answered in the documentation. Please note that being 11
>years old does *not* mean you get to skip the documentation.
If someone doesnt (yet) know their way around the documentation,
or cant find what they are seeking in the documentation, but they
need a quick answer to a question, then they are entitled to post
a question. It doesnt automatically follow that it is a 'stupid
question'.
I guess, in that case, that some 99% of all questions are "stupid".
Dont be so bloody patronising.
>
>Nobody has yet figured out how to actually kill anybody via Usenet.
>If somebody *had* figured out a way to do so, I'd probably be dead.
>
>> I really don't know how to keep repolling the Access database
>> waiting for a record to appear.
>
>Do you know how to get to your data from Perl in the first place? I
>recommend that you set up an ODBC data source and use DBI::ODBC.
>
>Do you know how to wait a few seconds (so that you're not constantly
>draining your machine's precious CPU time)?
>
> perldoc -f sleep
>
>Your program would have a section like this...
>
> while (still talking to the user) {
> if (there are more records in the table) {
> inform the user
> }
> sleep(some number of seconds)
> }
>
>Web technology issues are beyond the scope of this group, but you seem
>to know that already. I hope this helps.
---
Andrew Fry
"Time flies like an arrow. Fruit flies like a banana". (Groucho Marx).
------------------------------
Date: Tue, 23 Feb 1999 03:18:16 +0100
From: Le Tigre <LeTigre@Multimania.no-spam.com>
Subject: need help with PRINT
Message-Id: <36D20FE8.2D4BF2@Multimania.no-spam.com>
Hi,
I'm writing my perl scripts under win95 (with a perl of course! :=) and
testing them with PI3WEB, and when i've to write some big part of HTML
code, i'm doing like this:
------- cut here ------------
print << "END";
<h1>here goes my HTML</h1>
<p>all the <font color="#ffff00">HTML</font> code here.......
.......</p>
END
------- cut here ------------
instead of:
------- cut here ------------
print "<h1>here goes my HTML</h1>\n";
print <p>all the <font color=\"#ffff00\">HTML</font> code
here.......\n";
print "\n";
print "\n";
print ".......</p>\n";
------- cut here ------------
but when i've upload my script and try it under the WEB server, it
doesn't work !! :-(((
------- cut here ------------
syntax error in file index.pl at line 41, next 2 tokens ""END""
syntax error in file index.pl at line 86, next 2 tokens ""END""
Execution of index.pl aborted due to compilation errors.
[Mon Feb 22 18:13:21 1999] access to index.pl failed for 195.36.200.252,
reason: Premature end of script headers
------- cut here ------------
Could you please tell me why and explain me how to correct ??
PLZ answer to my private email: LeWEB@multimania.com
thanks a lot
------------------------------
Date: Tue, 23 Feb 1999 16:04:27 GMT
From: droby@copyright.com
Subject: Re: need help with PRINT
Message-Id: <7auji5$h39$1@nnrp1.dejanews.com>
In article <7jpA2.59575$641.162871@news.san.rr.com>,
"Steven T. Henderson" <stevenhenderson@prodigy.net> wrote:
> yup, this one drove me nuts too!
>
> >print << "END";
>
> .. just remove the SPACE between '<<' & "END" and you should be rolling.
>
Uh, no.
He should have been rolling already. The code as originally posted works
fine.
Either he didn't post an accurate cut of his code, or the real problem is
elsewhere in his code.
> Le Tigre wrote in message <36D20FE8.2D4BF2@Multimania.no-spam.com>...
> >Hi,
> >
> >I'm writing my perl scripts under win95 (with a perl of course! :=) and
> >testing them with PI3WEB, and when i've to write some big part of HTML
> >code, i'm doing like this:
> >------- cut here ------------
> >print << "END";
> ><h1>here goes my HTML</h1>
> ><p>all the <font color="#ffff00">HTML</font> code here.......
> >
> >
> >.......</p>
> >END
--
Don Roby
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 24 Feb 1999 01:45:44 +0100
From: Le Tigre <LeTigre@Multimania.no-spam.com>
Subject: Re: need help with PRINT
Message-Id: <36D34BB8.EE273B6@Multimania.no-spam.com>
> .. just remove the SPACE between '<<' & "END" and you should be rolling.
i did it, and it works fine now !!! thanks a lot!! :)
------------------------------
Date: Mon, 22 Feb 1999 19:32:25 -0600
From: "Steven T. Henderson" <stevenhenderson@prodigy.net>
Subject: Re: need help with PRINT
Message-Id: <7jpA2.59575$641.162871@news.san.rr.com>
yup, this one drove me nuts too!
>print << "END";
.. just remove the SPACE between '<<' & "END" and you should be rolling.
Le Tigre wrote in message <36D20FE8.2D4BF2@Multimania.no-spam.com>...
>Hi,
>
>I'm writing my perl scripts under win95 (with a perl of course! :=) and
>testing them with PI3WEB, and when i've to write some big part of HTML
>code, i'm doing like this:
>------- cut here ------------
>print << "END";
><h1>here goes my HTML</h1>
><p>all the <font color="#ffff00">HTML</font> code here.......
>
>
>.......</p>
>END
>------- cut here ------------
>
>
>instead of:
>------- cut here ------------
>print "<h1>here goes my HTML</h1>\n";
>print <p>all the <font color=\"#ffff00\">HTML</font> code
>here.......\n";
>print "\n";
>print "\n";
>print ".......</p>\n";
>------- cut here ------------
>
>
>but when i've upload my script and try it under the WEB server, it
>doesn't work !! :-(((
>
>------- cut here ------------
>syntax error in file index.pl at line 41, next 2 tokens ""END""
>syntax error in file index.pl at line 86, next 2 tokens ""END""
>Execution of index.pl aborted due to compilation errors.
>[Mon Feb 22 18:13:21 1999] access to index.pl failed for 195.36.200.252,
>reason: Premature end of script headers
>------- cut here ------------
>
>Could you please tell me why and explain me how to correct ??
> PLZ answer to my private email: LeWEB@multimania.com
>
>thanks a lot
------------------------------
Date: Wed, 24 Feb 1999 18:35:41 +0200
From: Ophir Marko <ophir@saifun.com>
Subject: Need Help With Simple Code
Message-Id: <36D42A5D.4FE9AA50@saifun.com>
What I want to do is open a file, search for the word("while", in this
case), put it into a new file, and then chmod 777 on the new file.
# /local/perl/bin/perl -w
$file = <ARGV>;
open(FILE, $file);
split;
while( $#_ =~ "while"){
open(FILE2, ">newfile");
print FILE2 $#_ \n;
close(FILE2);
chmod 777 newfile;
}
close(FILE);
------------------------------
Date: Wed, 24 Feb 1999 13:17:27 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: Ophir Marko <ophir@saifun.com>
Subject: Re: Need Help With Simple Code
Message-Id: <36D44237.604AD97C@giss.nasa.gov>
[courtesy copy of post sent to Ophir via email]
Ophir Marko wrote:
>
> What I want to do is open a file, search for the word("while", in this
> case), put it into a new file, and then chmod 777 on the new file.
>
> # /local/perl/bin/perl -w
> $file = <ARGV>;
> open(FILE, $file);
> split;
> while( $#_ =~ "while"){
> open(FILE2, ">newfile");
> print FILE2 $#_ \n;
> close(FILE2);
> chmod 777 newfile;
> }
> close(FILE);
hi Ophir,
here's one big, verbose, pedantic example for you:
#! /usr/local/bin/perl -w
use strict;
use vars qw($USAGE);
$USAGE = "USAGE: try.pl <in_file> <out_file> <from_word> <to_word>\n" .
"Change all occurrences of 'from_word' to 'to_word' in\n" .
"'in_file'. Write results to 'out_file'.\n";
main();
sub main
{
unless (@ARGV == 4) { die $USAGE; }
my ($in_name, $out_name, $from, $to) = @ARGV;
local (*INF, *OUTF);
open INF, "< $in_name" or die "can't open $in_name: $!";
open OUTF, "> $out_name" or die "can't open $out_name: $!";
change_file(\*INF, \*OUTF, $from, $to);
close INF;
close OUTF;
chmod 0777, $out_name;
}
sub change_file
{
my ($inf, $outf, $from, $to) = @_;
# next line could read "foreach (<$inf>)",
# this would slurp up the whole in file.
while (<$inf>)
{
s/$from/$to/;
print $outf $_;
}
}
--
"The number of UNIX installations has grown to 10, with more expected."
-- _The UNIX Programmer's Manual_, Second Edition, June, 1972.
------------------------------
Date: Wed, 24 Feb 1999 12:19:30 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Need Help With Simple Code
Message-Id: <MPG.113dfeb165f0f967989684@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <36D42A5D.4FE9AA50@saifun.com> on Wed, 24 Feb 1999 18:35:41
+0200, Ophir Marko <ophir@saifun.com> says...
> What I want to do is open a file, search for the word("while", in this
> case), put it into a new file, and then chmod 777 on the new file.
Your code is almost incomprehensible, but here's a line-by-line analysis
of what I think each statement attempts to do.
> # /local/perl/bin/perl -w
The space after '#' should be '!'. One gold star for '-w'.
You should get into the habit of now saying 'use strict;'
> $file = <ARGV>;
This says to read a line from the file whose filehandle is 'ARGV'. I
think you want to get the name from the first argument on the command
line, so:
$file = $ARGV[0] or die "Usage: $0 filename\n";
> open(FILE, $file);
Where is the test for failure of this open?
open(FILE, $file) or die "Couldn't read '$file'. $!\n";
> split;
Here you are splitting on white-space in $_, but you haven't assigned
anything to $_!
> while( $#_ =~ "while"){
This says 'If the number of elements in the array $@ matches 'while',
which is not likely at all. This loop will not be executed.
> open(FILE2, ">newfile");
Where is the test for failure of this open?
open(FILE, '>newfile') or die "Couldn't write 'newfile'. $!\n";
> print FILE2 $#_ \n;
You need commas to separate the elements of the list, and double=quotes
around the string literal "\n".
> close(FILE2);
> chmod 777 newfile;
You need commas to separate the elements of the list, and a check for
failure of this system call.
> }
> close(FILE);
You need a Perl primer, such as "Learning Perl" (the O'Reilly Llama
book).
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 25 Feb 1999 16:39:16 +0100
From: Philip Newton <Philip.Newton@datenrevision.de>
Subject: Re: Need Help With Simple Code
Message-Id: <36D56EA4.746AE036@datenrevision.de>
Larry Rosler wrote:
>
> In article <36D42A5D.4FE9AA50@saifun.com> on Wed, 24 Feb 1999 18:35:41
> +0200, Ophir Marko <ophir@saifun.com> says...
> > while( $#_ =~ "while"){
>
> This says 'If the number of elements in the array $@ matches 'while',
> which is not likely at all. This loop will not be executed.
... in the array @_ ...
> You need commas to separate the elements of the list, and double=quotes
> around the string literal "\n".
double-quotes? [with hyphen] (minor point)
> > close(FILE2);
> > chmod 777 newfile;
>
> You need commas to separate the elements of the list, and a check for
> failure of this system call.
And you need to specify the mode in octal (0777) -- 777 is 01411, which
is almost certainly not what you want anyway.
Cheers,
Philip
------------------------------
Date: 24 Feb 1999 12:06:47 GMT
From: "Sheila Eugenio" <seugenio@man.amis.com>
Subject: Need Help. Password checking CGI script.
Message-Id: <01be5fee$009f2f00$2bbe10ac@amipnet>
Hello all,
I just want to solicit some opinions regarding the perl that I have
created. There seems to be something wrong. I got the password checking
script from Ranson Johnson. I keep getting Access Denied message after
pressing the submit button. Thanks!
use DBI;
&parse;
$log = "d:\Inetpub\wwwroot\cgi-bin\rjea\people.log";
$login_page = ".../index.htm";
BEGIN {
$ENV{ORACLE_HOME} = '/home/oracle/product/7.x.x';
}
my $dbh = DBI->connect ('dbi:Oracle:', q{username/password@(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(Host = xxx.xx.xxx.xxx)(Port = xxxx))
(CONNECT_DATA = (SID = abcd)))}, "") || die "Database connection not
made: $DBI::errstr";
&whoareyou unless $FORM{'username'};
&whoareyou unless $FORM{'password'};
open (PEOPLE, "$log") || "Cannot find log file";
@lines = <PEOPLE>;
close (PEOPLE);
foreach $line (@lines){
($realname,$realpassword) = split(/\|/, $line);
$pwordlist{$realname} = $realpassword;
}
if (!$pwordlist{$FORM{'username'}}) {
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>Access Denied</TITLE></HEAD>\n";
print "<BODY><H1>Access Denied</H1>The username you supplied does not
exist.<P>\n";
print "<a href=http://amipnet/amip/rjea/index.htm>Please try again</a>\n";
print "</BODY>\n";
print "</HTML>\n";
} elsif ($FORM{'password'} ne $pwordlist{$FORM{'password'}}) {
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>Access Denied</TITLE></HEAD>\n";
print "<BODY><H1>Access Denied</H1>That is not the correct password for
username $FORM{'username'}.<P>\n";
print "<a href=http://amipnet/amip/rjea/index.htm>Please try
again</a>\n";
print "</BODY></HTML>\n";
} else {
my $sth = $dbh->prepare(q{
select criteria
from $username)}) || die "Can't prepare statement: $DBI::errstr";
my $rc = $sth->execute or die $DBI::errstr;
my $row_ref = $sth->fetchall_arrayref;
$maxcount = $sth->rows;
for ($i=0; $i=$maxcount; $i++) {
print "Content-type: text/html\n\n";
print "<HTML><BODY>\n";
print "<FORM method=POST
action=http://amipnet/cgi-bin/rjea/sample.pl><input
type=radio>$row_ref->[i]</p>\n";
print "</FORM></BODY></HTML>\n";
$sth->finish;
$dbh->disconnect;
}
}
sub whoareyou {
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>ERROR</TITLE></HEAD>\n";
print "<BODY bgcolor=ffffff>\n";
print "<CENTER>\n";
print "<H1><FONT color=0000ff>LOG IN</FONT></H1>\n";
print "<H2>You must enter username and password</H2>\n";
print "<a href=$login_page>Please try again</a>\n";
print "</BODY></HTML>\n";
}
sub parse {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
#split the name-value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs){
($name, $value) = split(/=/, $pair);
#Convert HEX to character
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
$FORM{$name}=$value;
}
}
------------------------------
Date: Wed, 24 Feb 1999 11:47:16 -0500
From: "Ken Hirsch" <kenhirsch@myself.com>
Subject: Re: Need Help. Password checking CGI script.
Message-Id: <7b1ae6$72i$1@holly.prod.itd.earthlink.net>
Sheila Eugenio wrote:
>$log = "d:\Inetpub\wwwroot\cgi-bin\rjea\people.log";
Backslashes need to be doubled \\ or use forward slashes or use single
quotes.
>open (PEOPLE, "$log") || "Cannot find log file";
Probably you meant
die "Cannot find log file";
------------------------------
Date: Mon, 22 Feb 1999 08:52:38 -0500
From: evil Japh <jeffp@crusoe.net>
Subject: Re: Need Random Link Script! HELP!
Message-Id: <Pine.GSO.3.96.990222082832.25986A-100000@crusoe.crusoe.net>
> #!/usr/local/bin/perl
>
> opendir(D, "/stud2/fwet/gdschrij/WWW"); #change this into your own dir
> @Filez = sort readdir(D);
> closedir(D);
> while ($File = shift @Filez)
> {
> if ($File =~ /.*\.html/)
> {
> push @HTMLs, $File;
> }
> }
> $numfiles=@HTMLs;
> srand();
> $random = int(rand(--$numfiles));
> print $HTMLs[$random];
Upon examination and execution of this program, you'll notice it will
never print the last link put into @HTMLs. Allow me to explain.
>From the perlfunc manpage, you can find that rand works as follows:
Returns a random fractional number greater than or equal to 0 and
less than the value of EXPR. (EXPR should be positive.) If EXPR
is omitted, the value 1 is used. Automatically calls srand()
unless srand() has already been called. See also srand().
Therefore, if @array has 5 elements, int(rand(@array-1)) will return any
integer from 0 to 3, because int() merely returns the integral portion of
the number supplied it.
I suggest the following program. It is compact and concise. It also
allows matches on files ending in .htm instead of .html, and it allows
for files ending in .HTM or .HTML.
#!/usr/bin/perl
opendir DIR, "/path/to/dir" or die "cannot open /path/to/dir: $!";
for ($i = 1; defined($_ = readdir DIR); $i++){
$i--, next unless /\.html?$/i;
rand($i) < 1 and ($file = $_);
}
closedir DIR;
print "File is $file\n"; # or whatever you want done
--
Jeff Pinyan (jeffp@crusoe.net)
www.crusoe.net/~jeffp
Crusoe Communications, Inc.
973-882-1022
www.crusoe.net
------------------------------
Date: Mon, 22 Feb 1999 10:07:07 +0100
From: Glad Deschrijver <gdschrij@eduserv2.rug.ac.be>
To: Nick Gray <nicktg@bellsouth.net>
Subject: Re: Need Random Link Script! HELP!
Message-Id: <Pine.GSO.3.96.990222100407.29432B-100000@eduserv2.rug.ac.be>
On Fri, 19 Feb 1999, Nick Gray wrote:
> I have looked long and hard for a Random Link Script that is NOT based on a
> user-set TXT or database file. One that will create an inventory of *.html
> files and just choose a random link from there. Help somebody, please!
#!/usr/local/bin/perl
opendir(D, "/stud2/fwet/gdschrij/WWW"); #change this into your own dir
@Filez = sort readdir(D);
closedir(D);
while ($File = shift @Filez)
{
if ($File =~ /.*\.html/)
{
push @HTMLs, $File;
}
}
$numfiles=@HTMLs;
srand();
$random = int(rand(--$numfiles));
print $HTMLs[$random];
#######################################
Hope this helps.
---------------------------------------------------------------------------
Glad Deschrijver gdschrij_AT_eduserv2_DOT_rug_DOT_ac_DOT_be
http://studwww.rug.ac.be/~gdschrij
---------------------------------------------------------------------------
Love conquers all things; let us too surrender to love.
-- Publius Vergilius Maro
------------------------------
Date: Mon, 22 Feb 1999 16:08:27 GMT
From: Ansis Ataols Berzins <ansis@my-dejanews.com>
Subject: Need script for HTTP filtering
Message-Id: <7arvdk$7kf$1@nnrp1.dejanews.com>
Hello!
I need a script for HTTP filtering, like
http://babelfish.altavista.com/
uses for translations.
Could you me recommend something?
Ansis Ataols Berzins
http://ansis.folklora.lv/
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 24 Feb 1999 15:39:30 +0100
From: Glad Deschrijver <gdschrij@eduserv2.rug.ac.be>
Subject: Re: Need script for HTTP filtering
Message-Id: <Pine.GSO.3.96.990224153721.19444L-100000@eduserv2.rug.ac.be>
On Mon, 22 Feb 1999, Ansis Ataols Berzins wrote:
> Hello!
>
> I need a script for HTTP filtering, like
> http://babelfish.altavista.com/
> uses for translations.
> Could you me recommend something?
$value =~ s/<([^>]|\n)*>//g; # Removes html-tags in $value
---------------------------------------------------------------------------
Glad Deschrijver gdschrij_AT_eduserv2_DOT_rug_DOT_ac_DOT_be
http://studwww.rug.ac.be/~gdschrij
---------------------------------------------------------------------------
"Once ze rockets go up, who cares vere they come down, zat's not my department."
-- Wehrner von Braun
------------------------------
Date: Thu, 25 Feb 1999 09:52:55 GMT
From: Ansis Ataols Berzins <ataols@lanet.lv>
Subject: Re: Need script for HTTP filtering
Message-Id: <7b36hk$es7$1@nnrp1.dejanews.com>
> > I need a script for HTTP filtering, like
> > http://babelfish.altavista.com/
> > uses for translations.
> > Could you me recommend something?
>
> $value =~ s/<([^>]|\n)*>//g; # Removes html-tags in $value
Thanks, but you are not understood right, what I need. I need a script, which
accepts links as parametters, GETs or POSTs these URLs, replaces all relative
and absolute links in document to the same links via my script and returns
document to user. It is like babelfish translator do, but only without
translation.
Ansis Ataols Berzins
http://ansis.folklora.lv/
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 23 Feb 1999 20:25:27 -0500
From: "Bill Jones" <bill@fccj.org>
Subject: Re: Need script for HTTP filtering
Message-Id: <36d35460.0@usenet.fccj.cc.fl.us>
I didn't write this and I cannot
support it, but -
How about:
#!/usr/local/bin/perl
# Ex. Usage: bash$ perl bablefish.pl -g
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
use HTTP::Headers;
%to = (-f => 'en_fr', #french
-g => 'en_de', #german
-i => 'en_it', #italian
-p => 'en_pt', #portuguese
-s => 'en_es'); #spanish
%from = (-f => 'fr_en',
-g => 'de_en',
-i => 'it_en',
-p => 'pt_en',
-s => 'es_en');
$language = shift || '-f';
$content = `/usr/games/fortune`; #substitute something appropriate here
print "$content\n";
$translation = &babel($content, $to{$language});
print "$translation\n";
$retranslation = &babel($translation, $from{$language});
print "$retranslation\n";
foreach (@ARGV) {
$translation = &babel($retranslation, $to{$_});
print "$translation\n";
$retranslation = &babel($translation, $from{$_});
print "$retranslation\n";
}
sub babel {
my $content = shift;
my $language_pair = shift;
$content =
"doit=done&languagepair=$language_pair&urltext=".$content;
my $content_length = length($content);
my $header = new HTTP::Headers([Accept => 'text/html'],
[UserAgent => 'misfortune'],
[Content-type =>
'application/x-www-form-urlencoded'],
[Content-length => $content_length]);
my $request = new HTTP::Request 'POST',
'http://babelfish.altavista.digital.com/cgi-bin/translate?',
$header, $content;
my $ua = new LWP::UserAgent;
my $response = new HTTP::Response;
$response = $ua->request($request);
my $response_body = $response->content();
$response_body =~ m!<td align="left">\n\n(.+?)</td><td><img
border=0 src="/gifs/clear.gif" width="15" height="0"></td></tr>!s;
my $translation = $1;
return $translation;
}
HTH,
-Sneex- :
----------
In article <7arvdk$7kf$1@nnrp1.dejanews.com>, Ansis Ataols Berzins
<ansis@my-dejanews.com> wrote:
> Hello!
>
> I need a script for HTTP filtering, like
> http://babelfish.altavista.com/
> uses for translations.
> Could you me recommend something?
>
>
> Ansis Ataols Berzins
> http://ansis.folklora.lv/
>
>
>
>
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Thu, 25 Feb 1999 02:16:33 -0800
From: Jeff Zucker <jeff@vpservices.com>
To: Ansis Ataols Berzins <ataols@lanet.lv>
Subject: Re: Need script for HTTP filtering
Message-Id: <36D52301.DDAB66F4@vpservices.com>
[emailed and posted]
Ansis Ataols Berzins wrote:
> Thanks, but you are not understood right, what I need. I need a
> script, which accepts links as parametters, GETs or POSTs these URLs,
> replaces all relative and absolute links in document to the same links
> via my script and returns document to user. It is like babelfish
> translator do, but only without translation.
It's easily done with LWP module. Retrieve pages, modify, then store or
display them. In fact you can use it *with* babblefish to translate an
entire site on the fly (though I wouldn't recommend that because of the
quality of the translation and because of copyright issues). I've made
a 38 line script which will submit a url to babblefish using LWP, get
back the translated page, replace all the links with ones that send
those linked pages to babblefish by LWP for the same process so when
user clicks on any link on a translated page, it sends that link to get
translated and then displays it without ever bringing the user off the
original site to altavista. This same method would work on other sites
without the translation process.
--
Jeff Zucker Co-coordinator, UNICEF Voices of Youth
\/ http://www.unicef.org/voy/
-<>-
/\ CTO, Virtual Production Services LLC
jeff@vpservices.com http://www.vpservices.com/jeff/
------------------------------
Date: 25 Feb 1999 07:54:16 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Need script for HTTP filtering
Message-Id: <m1yalm1ntj.fsf@halfdome.holdit.com>
>>>>> "Ansis" == Ansis Ataols Berzins <ataols@lanet.lv> writes:
Ansis> Thanks, but you are not understood right, what I need. I need
Ansis> a script, which accepts links as parametters, GETs or POSTs
Ansis> these URLs, replaces all relative and absolute links in
Ansis> document to the same links via my script and returns document
Ansis> to user. It is like babelfish translator do, but only without
Ansis> translation.
This is almost exactly what my "cookie jar" CGI script does,
described in <URL:http://www.stonehenge.com/merlyn/WebTechniques/>.
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 4987
**************************************