[18723] in Perl-Users-Digest
Perl-Users Digest, Issue: 891 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 14 00:05:50 2001
Date: Sun, 13 May 2001 21:05:08 -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: <989813108-v10-i891@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 13 May 2001 Volume: 10 Number: 891
Today's topics:
[ merging member folders ] <Sinema_BTVS@SPAM-hotmail.com>
Concenate Columns <jtjohnston@courrier.usherb.ca>
Re: Concenate Columns <jfreeman@tassie.net.au>
Re: DOS Perl convering LF to CR/LF (Alan Barclay)
Re: Help with my html to txt perl script <iltzu@sci.invalid>
Re: HELP: loading a hash of anon subs from file... <jfreeman@tassie.net.au>
How do I run another cgi? <bop@mypad.com>
Re: How do I run another cgi? <bop@mypad.com>
How to get cookie from a mod_perl proxy <firestar@MailAndNews.com>
Http REFFERER -> IP ADDR <i.m.knight@btinternet.com>
Re: Http REFFERER -> IP ADDR (Logan Shaw)
Re: Http REFFERER -> IP ADDR (Alan Barclay)
Re: Http REFFERER -> IP ADDR <tony_curtis32@yahoo.com>
Re: Http REFFERER -> IP ADDR <godzilla@stomp.stomp.tokyo>
Re: Http REFFERER -> IP ADDR (Dave Bailey)
Re: Need Help: Pattern Matching Etc. <jfreeman@tassie.net.au>
Net::SMTP problem <i-Kan@GETRIDOFBalkanEnergyReview.com>
Re: perl -c to file <jfreeman@tassie.net.au>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 13 May 2001 19:01:07 -0500
From: "Sinema" <Sinema_BTVS@SPAM-hotmail.com>
Subject: [ merging member folders ]
Message-Id: <NeFL6.1974$OS1.371810@news1.iquest.net>
Howdy,
I have a site that uses several different scripts that ask the member to
register with them in order to use that service.
I was curious if there was a way to make some page that allows the user to
register with all the scripts ?
I use on script for stories, one script for image galleries, and then I'm
thinking about installing Newspro and Ultimate BB..
Which would end up with 4 different register sections.. I just am curious
if there was a way to merge them so 1 person can register 1 nick name and
use it through all the features
Thanks for any help :-)
--
Regards
Sinema - Sinema_BTVS@SPAM-hotmail.com
< remove SPAM- to reply >
--- Start Codex Buffy Code 0.1 -------------------------------------
ECa S+++(S++)>S+ O! M+++(M+)>M P B* G(G-) W+(W)>W-- X! C* A+++ Z!
--- End Codex Buffy Code --- http://www.planetx.com/buffy/code/ ----
------------------------------
Date: Sun, 13 May 2001 20:30:08 -0400
From: jtjohnston <jtjohnston@courrier.usherb.ca>
Subject: Concenate Columns
Message-Id: <3AFF2710.BBDEB1E7@courrier.usherb.ca>
Hi,
I already have two database files "firsthalf.txt" and "secondhalf.txt".
Without getting into a looong explanation, a very expensive software
(www.notabene.com) can only extract 12 fields at a time.
Their contents, respectively, look a bit like this:
"firsthalf.txt"
1¶field1¶field2¶field3¶field4¶field5¶field6¶field7¶field8¶field9¶field10¶field11¶field12
2¶field1¶field2¶field3¶field4¶field5¶field6¶field7¶field8¶field9¶field10¶field11¶field12
...
100¶field1¶field2¶field3¶field4¶field5¶field6¶field7¶field8¶field9¶field10¶field11¶field12
"secondhalf.txt"
1¶field13¶field14¶field15¶field16¶field17¶field18¶field19¶field20¶field21¶field22¶field23¶field24
2¶field13¶field14¶field15¶field16¶field17¶field18¶field19¶field20¶field21¶field22¶field23¶field24
...
100¶field13¶field14¶field15¶field16¶field17¶field18¶field19¶field20¶field21¶field22¶field23¶field24
I need to concenate, not the files, but the columns and output to a new
text file. Thus where "field12" ends, I want to add "field13" up to
field "24".
The output will look like this:
1¶field1¶field2¶field3¶field4¶field5¶field6¶field7¶field8¶field9¶field10¶field11¶field12¶field13¶field14¶field15¶field16¶field17¶field18¶field19¶field20¶field21¶field22¶field23¶field24
2¶field1¶field2¶field3¶field4¶field5¶field6¶field7¶field8¶field9¶field10¶field11¶field12¶field13¶field14¶field15¶field16¶field17¶field18¶field19¶field20¶field21¶field22¶field23¶field24
...
100¶field1¶field2¶field3¶field4¶field5¶field6¶field7¶field8¶field9¶field10¶field11¶field12¶field13¶field14¶field15¶field16¶field17¶field18¶field19¶field20¶field21¶field22¶field23¶field24
Newbie question ... but :) Can someone help me come up with something?
John
(An email post & reply would help ifyou don't mind. :)
------------------------------
Date: Mon, 14 May 2001 12:13:17 +1000
From: James freeman <jfreeman@tassie.net.au>
Subject: Re: Concenate Columns
Message-Id: <3AFF3F3D.64776E01@tassie.net.au>
[ posted clpmisc and CC author]
jtjohnston wrote:
> Hi,
>
> I already have two database files "firsthalf.txt" and "secondhalf.txt".
> Without getting into a looong explanation, a very expensive software
> (www.notabene.com) can only extract 12 fields at a time.
>
> Their contents, respectively, look a bit like this:
>
> "firsthalf.txt"
> 1¶field1¶field2¶field3¶field4¶field5¶field6¶field7¶field8¶field9¶field10¶field11¶field12
>
> 2¶field1¶field2¶field3¶field4¶field5¶field6¶field7¶field8¶field9¶field10¶field11¶field12
>
> ...
> 100¶field1¶field2¶field3¶field4¶field5¶field6¶field7¶field8¶field9¶field10¶field11¶field12
>
> "secondhalf.txt"
> 1¶field13¶field14¶field15¶field16¶field17¶field18¶field19¶field20¶field21¶field22¶field23¶field24
>
> 2¶field13¶field14¶field15¶field16¶field17¶field18¶field19¶field20¶field21¶field22¶field23¶field24
>
> ...
> 100¶field13¶field14¶field15¶field16¶field17¶field18¶field19¶field20¶field21¶field22¶field23¶field24
>
> I need to concenate, not the files, but the columns and output to a new
> text file. Thus where "field12" ends, I want to add "field13" up to
> field "24".
> The output will look like this:
>
> 1¶field1¶field2¶field3¶field4¶field5¶field6¶field7¶field8¶field9¶field10¶field11¶field12¶field13¶field14¶field15¶field16¶field17¶field18¶field19¶field20¶field21¶field22¶field23¶field24
>
> 2¶field1¶field2¶field3¶field4¶field5¶field6¶field7¶field8¶field9¶field10¶field11¶field12¶field13¶field14¶field15¶field16¶field17¶field18¶field19¶field20¶field21¶field22¶field23¶field24
>
> ...
> 100¶field1¶field2¶field3¶field4¶field5¶field6¶field7¶field8¶field9¶field10¶field11¶field12¶field13¶field14¶field15¶field16¶field17¶field18¶field19¶field20¶field21¶field22¶field23¶field24
>
> Newbie question ... but :) Can someone help me come up with something?
>
> John
> (An email post & reply would help ifyou don't mind. :)
#!/usr/bin/perl
use strict;
# define a hash to contain our joined record
my %complete;
# Grab some data into arrays, just a bit for the demo
my @data = <DATA>;
my @first = ($data[0],$data[1]);
my @second = ($data[2],$data[3]);
# Make a hash keyed on record number
for (@first) {/^(\d+)(.*)$/;$complete{$1} = $1.$2}
# Add the second record to the appropriate bit as defined by our key
for (@second) {/^(\d+)(.*)$/;$complete{$1} .= $2}
# prove it works
for $key(keys %complete) {print "$key => $complete{$key}\n";}
__DATA__
1¶field1¶field2¶field3¶field4¶field5¶field6¶field7¶field8¶field9¶field10¶field11¶field12
2¶field1¶field2¶field3¶field4¶field5¶field6¶field7¶field8¶field9¶field10¶field11¶field12
1¶field13¶field14¶field15¶field16¶field17¶field18¶field19¶field20¶field21¶field22¶field23¶field24
2¶field13¶field14¶field15¶field16¶field17¶field18¶field19¶field20¶field21¶field22¶field23¶field24
Cheers
James
PS I'll leave you to work out how to get the real data into the arrays. It's in the FAQ if you have problems
--
################################################################
# #
# A Thought on Perl Poetry and the Immortal JAPH #
# #
# I, require strict* and do not require warnings*. My answer #
# equals reference you unless answer equals 42. Question: If #
# defined, by this paradigm, do you do, the hacker foo? Now #
# join the data (why Fs & Os?), so the space or newline goes #
# Character evaluate: Reverse split null, then for each foo: #
# You ate foo, but I ate two. Answer -> Join with null, sort #
# the spots, and print it join the dots. Go now and exit, do #
# not die, else go to question and answer why? JAPH! (c)JADF #
# #
################################################################
I, require strict and do(not require warnings); my $answer = \$u
unless $answer == '42'; Question: if(defined by this_paradigm do
you_do_the_hacker_foo(??)){sub AUTOLOAD{$_=$now=join'the',<DATA>
;y?FO?01?; s.o|the| |\n..goe;s/(.{7})/(chr(eval'($u,$ate)=(0,1);
foreach $foo(reverse split "",$1){$u+=$ate*$foo;$but_I=$ate*=2;}
$$answer'))/eg;$_= join'',sort/(..)/g and print join'',/.(.)/go;
$now and exit, do(not die)}}else{goto Question and $answer;y???}
__DATA__
OOFFOOOOOFOO OFOO OOFFFOOOFFO FOOO FFOO OFFO
FFFOOFOOOFOF OFFFFOOF OFFFOOFOOOOO OFOO FOFO FFFF
FOOO FOOF OOFO FOOO OFOF OOOO FFOF OOOF
OFOF OOFO FFFO OFFF OOOO OFFO OOOF FFFO
OFFO FOFOOOFFOFFO FFFFFOOOFOFF OOFFFFOOOFFO FFOO
OFOF FOOFFOFOFOFF FFFOOFFOOFO FFFFFOOOOFOF OOOF
FFOO OOOF FFOO OFOO FFOO OFFF FOOO
FF OFOO FOOO OOOF FOFO OOFO OFFO
OOFFOFOO FFFO FOOO FOFO OOFO FFOO OOFO
FFOOOF OOOO OFFO FOOO OOFF OFOF FFFO
------------------------------
Date: 14 May 2001 01:47:37 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: DOS Perl convering LF to CR/LF
Message-Id: <989804856.862572@elaine.furryape.com>
In article <kldaft8qmicvt81nlo3v852egnt470bgbj@4ax.com>,
Bart Lateur <bart.lateur@skynet.be> wrote:
>As you noticed, "\n" is chr(10), just as in Unix. So it's just one
>character, not two. Conversion from CRLF to "\n" happens on input, and
\n is chr(13) on Macs. You can generalize that to \n is always the
end of line character on text files.
------------------------------
Date: 13 May 2001 22:14:59 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Help with my html to txt perl script
Message-Id: <989789194.12958@itz.pp.sci.fi>
In article <9dmhm9$8qd$1@newsg4.svr.pol.co.uk>, Ciaran McCreesh wrote:
>
>#!/usr/bin/perl
Since I'm picking nits already, I might as well suggest:
#!/usr/bin/perl -Tw
use strict;
>my $cgi = CGI::new(); # is this the approved way? not sure...
my $cgi = CGI->new(); # this is the correct way
"my $cgi = new CGI;" will also work, but I'd recommed staying away from
indirect object syntax in general. (Read the "WARNING" section of the
perlobj manual page for reasons why.) Your original syntax might work
in this case too, but it's not how it's supposed to be done. If it does
work for one version of CGI.pm, it might not work for the next.
># change next line to match your server
>my $filename = '/home/htdocs/' . $cgi->param("file") . '.html';
If you use the -T switch on the first line, you'll need to untaint the
filename here. The one thing you really need to watch out for is "../",
but in general you should only allow what you *know* to be safe.
my $file = $cgi->param("file");
defined $file and length $file or die "No filename!\n";
$file =~ m!^([\w-][\w.-]*(?:/[\w-][\w.-]*)*)$!
or die "Bad filename '$file'\n";
$file = "/home/htdocs/$1.html";
> open FILE, '/home/htdocs/' . $filename or die $!;
Oops, now you've prepended "/home/htdocs/" twice to the filename..
> flock FILE, LOCK_SH;
While this is indeed useful if some other program might acquire an
exclusive lock on the file to modify it, it's a no-op otherwise.
Also, you forgot to use the module that defines LOCK_SH.
>Of course, you'll have to be extremely careful you don't let anyone see
>any important files that way -- a certain bank which shall remain
>nameless uses Java for their online stuff, and it isn't difficult to get
>hold of their password file that way... The forcing .html and hard-coding
>the directory helps, but you might want to put in a few more checks (easy
>exercise for the reader...).
The code I showed above should prevent anyone from viewing dotfiles or
any files outside the document root. Taint mode is useful in forcing
one to think about such things, as well as catching bugs.
>That's just a rough outline, anyway. Play around with it until it does
>what you want -- it's a good way to learn.
Nothing wrong with rough outlines, though you might want to explicitly
mention the magic words "untested code, might not even compile".
I should however mention that you are generally expected to use -w and
"use strict" in any code you post here, except maybe for oneliners.
Yes, that goes even for rough outlines. That's because it's useful --
"use strict" would've caught your LOCK_SH bug, for example -- and also
because we don't want to encourage newbies to omit them.
Some people say that every CGI script should have taint mode enabled. I
wouldn't go quite that far, but it's still a good idea to use it.
--
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla / Kira -- do not feed the troll.
------------------------------
Date: Mon, 14 May 2001 11:11:08 +1000
From: James freeman <jfreeman@tassie.net.au>
Subject: Re: HELP: loading a hash of anon subs from file...
Message-Id: <3AFF30AC.119B9DCB@tassie.net.au>
Bruno Boettcher wrote:
> hello!
>
> i am in the progress of writing an irc bot in perl, since it has to
> answer to a lot of triggers, i put the triggers into a hash with
> references to anon subroutines, like this:
>
> 'PART' => sub
> {
> my $sLine = shift;
> $sLine =~ s/:(.*)$/$1/;
> ... and some more code ....
> },
>
> 'JOIN' => sub
> {
> ... even more code ...
> }
>
> and then in the event loop i make :
> if ($reactions->{$commandtag})
> {
> &{$reactions->{$commandtag}}( $sLine, $sGtmp );
> }
>
> now this works fine, but now i thought, that it would be nice to have
> those triggers outside of the main file. That way i would be able to
> modify the behaviour of the bot without needing to restart it, only
> issue a reload command ...
>
> so i put all the lines of the hash into a ':' separated file. Loaded
> that file into the hash, but when i try to use the subs, i get the
> following error: Can't use string ("sub { SendServer( 'PRIVMSG '.$se")
> as a subroutine ref while "strict refs" in use at ./zebot.pl line 398,
> <GEN1> line 34.
Although the entire message is difficult to decipher in the context of the code
you have posted the basic problem is the "strict refs" part. Under strict you
may only use hard references. You are trying to access the sub via a symbolic
ref, thus the error. You might try either of the following:
no strict;
no strict 'refs';
>
>
> Now i suppose that the error message is truncated and that the line was
> complete, at least in the hash its complete.....
>
> So i am surely missing something obvious here, but i don't get it....
> i tryed to eval the incoming subs, but this was even worse, eval doesn'T
> seem to return a reference of any sort....
You have accidentally used sym refs
>
>
> so i would really need some help here...
perldoc perlref << check out the bit on symbolic references
post real code, particularly the actual lines that generate the error!
Cheers
James
[snip]
--
################################################################
# #
# A Thought on Perl Poetry and the Immortal JAPH #
# #
# I, require strict* and do not require warnings*. My answer #
# equals reference you unless answer equals 42. Question: If #
# defined, by this paradigm, do you do, the hacker foo? Now #
# join the data (why Fs & Os?), so the space or newline goes #
# Character evaluate: Reverse split null, then for each foo: #
# You ate foo, but I ate two. Answer -> Join with null, sort #
# the spots, and print it join the dots. Go now and exit, do #
# not die, else go to question and answer why? JAPH! (c)JADF #
# #
################################################################
I, require strict and do(not require warnings); my $answer = \$u
unless $answer == '42'; Question: if(defined by this_paradigm do
you_do_the_hacker_foo(??)){sub AUTOLOAD{$_=$now=join'the',<DATA>
;y?FO?01?; s.o|the| |\n..goe;s/(.{7})/(chr(eval'($u,$ate)=(0,1);
foreach $foo(reverse split "",$1){$u+=$ate*$foo;$but_I=$ate*=2;}
$$answer'))/eg;$_= join'',sort/(..)/g and print join'',/.(.)/go;
$now and exit, do(not die)}}else{goto Question and $answer;y???}
__DATA__
OOFFOOOOOFOO OFOO OOFFFOOOFFO FOOO FFOO OFFO
FFFOOFOOOFOF OFFFFOOF OFFFOOFOOOOO OFOO FOFO FFFF
FOOO FOOF OOFO FOOO OFOF OOOO FFOF OOOF
OFOF OOFO FFFO OFFF OOOO OFFO OOOF FFFO
OFFO FOFOOOFFOFFO FFFFFOOOFOFF OOFFFFOOOFFO FFOO
OFOF FOOFFOFOFOFF FFFOOFFOOFO FFFFFOOOOFOF OOOF
FFOO OOOF FFOO OFOO FFOO OFFF FOOO
FF OFOO FOOO OOOF FOFO OOFO OFFO
OOFFOFOO FFFO FOOO FOFO OOFO FFOO OOFO
FFOOOF OOOO OFFO FOOO OOFF OFOF FFFO
------------------------------
Date: Sun, 13 May 2001 18:34:58 -0400
From: "flash" <bop@mypad.com>
Subject: How do I run another cgi?
Message-Id: <9XDL6.25411$h%.4238238@news20.bellglobal.com>
Hello I wrote a cgi that runs another cgi and prints the output.
It works right in the shell window but not in the web browser, Why would it
be differant?
------------------------------
Date: Sun, 13 May 2001 18:41:17 -0400
From: "flash" <bop@mypad.com>
Subject: Re: How do I run another cgi?
Message-Id: <11EL6.25445$h%.4243476@news20.bellglobal.com>
Ok i know what is wrong.
It prints some stuff to the error.log file, so it must be sending to STDERR,
how can i redirect STDERR to STDOUT?
"flash" <bop@mypad.com> wrote in message
news:9XDL6.25411$h%.4238238@news20.bellglobal.com...
> Hello I wrote a cgi that runs another cgi and prints the output.
>
> It works right in the shell window but not in the web browser, Why would
it
> be differant?
>
>
>
------------------------------
Date: Sun, 13 May 2001 23:42:22 -0400
From: Firestar <firestar@MailAndNews.com>
Subject: How to get cookie from a mod_perl proxy
Message-Id: <3B30139A@MailAndNews.com>
Hi, I am writing a perl_mod script for apache that will act as a proxy to
intercept all requests that comes through my proxy. I want to set a cookie
in
the client's browser (to store a session ID) and retrieve it each time the
user make a request to other URL (assuming he has set my proxy as his proxy
in
his browser configuration).
My question is: Am i able to get the cookie i have set, from the client? I
can
set the cookie for the client, but I have not been able to retrieve it so
far:(. Any help here is much appreciated.
Regards,
Firestar
------------------------------
Date: Sun, 13 May 2001 23:42:48 +0100
From: "Ian Knight" <i.m.knight@btinternet.com>
Subject: Http REFFERER -> IP ADDR
Message-Id: <9dn2o5$1rh$1@plutonium.btinternet.com>
How would i get the IP of the ENV variable HTTP_REFERER.
The HTTP_REFERER return eg www.somedomain.com i want 123.456.789.010 or
whatever
i can do a system("/usr/bin/nslookup - www.domain.com"); and it OUTPUTS a
text based string with it in.
Can i parse the output of the sytem command into a variable and use pattern
matching to find the IP address.
Thanks in Advance
ANY HELP GREATLY APPRECIATED!!!
------------------------------
Date: 13 May 2001 19:11:25 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Http REFFERER -> IP ADDR
Message-Id: <9dn7rd$itd$1@ahab.cs.utexas.edu>
In article <9dn2o5$1rh$1@plutonium.btinternet.com>,
Ian Knight <i.m.knight@btinternet.com> wrote:
>How would i get the IP of the ENV variable HTTP_REFERER.
>
>The HTTP_REFERER return eg www.somedomain.com i want 123.456.789.010 or
>whatever
>
>i can do a system("/usr/bin/nslookup - www.domain.com"); and it OUTPUTS a
>text based string with it in.
"perldoc -f gethostbyname" will explain how.
Hope that helps.
- Logan
--
my your his her our their _its_
I'm you're he's she's we're they're _it's_
------------------------------
Date: 14 May 2001 00:05:40 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: Http REFFERER -> IP ADDR
Message-Id: <989798662.41652@elaine.furryape.com>
In article <9dn2o5$1rh$1@plutonium.btinternet.com>,
Ian Knight <i.m.knight@btinternet.com> wrote:
>How would i get the IP of the ENV variable HTTP_REFERER.
>
>The HTTP_REFERER return eg www.somedomain.com i want 123.456.789.010 or
>whatever
You want gethostbyaddr(); Check perlfunc for the details. However, there
is no gaurantee that the addresss given in HTTP_REFERER is resolvable by
you. If the user follows the link from a private intranet, then the name
could only be resolvable by systems on that private intranet.
------------------------------
Date: 13 May 2001 19:59:59 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Http REFFERER -> IP ADDR
Message-Id: <87k83kiw34.fsf@limey.hpcc.uh.edu>
>> On 14 May 2001 00:05:40 GMT,
>> gorilla@elaine.furryape.com (Alan Barclay) said:
> In article <9dn2o5$1rh$1@plutonium.btinternet.com>,
> Ian Knight <i.m.knight@btinternet.com> wrote:
>> How would i get the IP of the ENV variable
>> HTTP_REFERER.
>>
>> The HTTP_REFERER return eg www.somedomain.com i want
>> 123.456.789.010 or whatever
(789 ????? :-)
> You want gethostbyaddr(); Check perlfunc for the
^^^^
name() assuming it *is* a name.
Net::DNS may be an alternative route to take.
> details. However, there is no gaurantee that the
> addresss given in HTTP_REFERER is resolvable by you. If
> the user follows the link from a private intranet, then
> the name could only be resolvable by systems on that
> private intranet.
Wouldn't you get the proxy/NAT address in that case?
--
Just reach into these holes. I use a carrot.
------------------------------
Date: Sun, 13 May 2001 19:53:56 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Http REFFERER -> IP ADDR
Message-Id: <3AFF48C4.47A585A9@stomp.stomp.tokyo>
Ian Knight wrote:
> How would i get the IP of the ENV variable HTTP_REFERER.
(snipped)
You should know, not all data provided by a
referral variable will be a hostname. I have
log entries ranging from news servers to
local pc bookmark files, examples:
news://news.pnet.com
c://browser/bookmark.htm
A news server URL will cause a bug. Clearly
a referral from within a local machine, this
is, a local disk drive, cannot be resolved!
As is my habit, a test script follows my
signature. I have created an array simply
for my convenience and to provide ample
samples of returns. Your interest will
most likely be the heart of my code.
My inclusion of news servers is to exemplify
a little known bug. You will discover this
script of mine will crash and burn when it
encounters a news server address, after
printing the preceeding data returns.
All appears normal, but is not. If you
work on learning why this happens, you
will benefit by gained knowledge about
something, of which, few know.
This is the heart of my code:
$hostname = substr ($hostname, 7, index ($hostname, "/", 7) - 7);
$ip_address = inet_ntoa (inet_aton($hostname));
My use of substring is to grab only the host name
of interest. All else is removed. Second line
brings the Socket module into play, one of only
three or four modules I suggest for use. Use your
referral data where I have $hostname. Do remember,
your referral data should be cleaned up first.
It would be of interest to read what you discover
about news servers and IP address lookup using
this type of script.
Godzilla!
--
#!perl
print "Content-type: text/plain\n\n";
use Socket;
@Array = qw (http://search.lycos.com/raf/default.asp
http://ph.lycosasia.com/srch/more.html
http://www.altavista.com/iepane?A&Query+String&Here
http://buscador.ya.com/scripts/bavanzada
http://groups.google.com/groups
http://la.znet.com/~callgirl/rockmusi.html
news://news.ttnet.net.tr
news://news.fh-flensburg.de);
foreach $hostname (@Array)
{
$hostname = substr ($hostname, 7, index ($hostname, "/", 7) - 7);
$ip_address = inet_ntoa (inet_aton($hostname));
print "Referral: $hostname\nIP Address: $ip_address\n\n";
}
exit;
PRINTED RESULTS:
________________
Referral: search.lycos.com
IP Address: 209.202.192.49
Referral: ph.lycosasia.com
IP Address: 202.160.249.218
Referral: www.altavista.com
IP Address: 209.73.164.91
Referral: buscador.ya.com
IP Address: 212.106.193.39
Referral: groups.google.com
IP Address: 216.239.35.119
Referral: la.znet.com
IP Address: 207.167.96.1
------------------------------
Date: 14 May 2001 03:56:32 GMT
From: dave@sydney.daveb.net (Dave Bailey)
Subject: Re: Http REFFERER -> IP ADDR
Message-Id: <slrn9fubjl.3rm.dave@sydney.daveb.net>
On Sun, 13 May 2001 19:53:56 -0700, Godzilla!
<godzilla@stomp.stomp.tokyo> wrote:
>Ian Knight wrote:
>
>> How would i get the IP of the ENV variable HTTP_REFERER.
[...]
>You should know, not all data provided by a
>referral variable will be a hostname. I have
>log entries ranging from news servers to
>local pc bookmark files, examples:
>
>news://news.pnet.com
>
>c://browser/bookmark.htm
>
>A news server URL will cause a bug.
[...]
>My inclusion of news servers is to exemplify
>a little known bug. You will discover this
>script of mine will crash and burn when it
>encounters a news server address, after
>printing the preceeding data returns.
The bug is little known because it only exists in your code, which
breaks any time it encounters a string which does not contain a '/'
outside of the first seven characters. I cannot emphasize enough
how much you stand to gain from learning how to use regular
expressions to do pattern matching. For example:
[...]
>@Array = qw (http://search.lycos.com/raf/default.asp
> http://ph.lycosasia.com/srch/more.html
> http://www.altavista.com/iepane?A&Query+String&Here
> http://buscador.ya.com/scripts/bavanzada
> http://groups.google.com/groups
> http://la.znet.com/~callgirl/rockmusi.html
> news://news.ttnet.net.tr
> news://news.fh-flensburg.de);
foreach ( @Array ) {
if ( m!(https?|news)://([^\s/]+)! ) {
my $a = inet_aton($2);
print inet_ntoa($a), "\n" if $a;
}
}
Instead of continually trying to force index and substr to work in
situations naturally suited to regular expressions, make an effort
to learn what regular expressions are and how to use them.
--
Dave Bailey
davidb54@yahoo.com
------------------------------
Date: Mon, 14 May 2001 10:47:48 +1000
From: James freeman <jfreeman@tassie.net.au>
Subject: Re: Need Help: Pattern Matching Etc.
Message-Id: <3AFF2B34.6BC63361@tassie.net.au>
phookie wrote:
> <TD LOTUS_VALUE="BLANK" ALIGN=LEFT><font color="#ffffff"
> size="3">1234.56</font></TD>
> <TD LOTUS_VALUE="ERR" ALIGN=CENTER><font color="#000000"
> size="3">1234.56</font></TD>
> <TD LOTUS_VALUE="ERR" ALIGN=RIGHT><font color="#ffffff"
> size="3">1234.56</font></TD>
> Etc....
You really need to use a module like HTML::TokeParser to do this reliably.
> I need to replace the "TD" tag data with simply, no matter what the
> attributes/values are with simply <td class="abc"> remove the font tag data
> completely, parse out the numeric, remove the ending font tag and keeping the
> TD tag
> sometimes i need to remove the entire line if the numeric is not in a specific
> range
>
If your specification is exact this does it. Newlines between <TD>.....</TD> are
NOT tolerated by this script in its current form. You can fix that if you want to,
after all can't spoon feed you ;-)
#!/usr/bin/perl -w
use strict;
my $tag = qr/\s*<[^>]*?>\s*/;
my $replace = '<td class="abc">';
my $lowest = 100;
my $highest = 1500;
foreach my $record (<DATA>) {
chomp $record;
next unless $record !~ m/^\s*$/;
print "Old record: $record\n";
$record =~ s#^\s*<TD\s+LOTUS[^>]*?>$tag([\d\.]+)$tag</TD>#$replace$1</TD>#;
$record = '' if $1 < $lowest or $1 > $highest; # delete it
print "New record: $record\n";
}
__DATA__
<TD LOTUS_VALUE="BLANK" ALIGN=LEFT><font
color="#ffffff"size="3">1234.56</font></TD>
<TD LOTUS_VALUE="ERR" ALIGN=CENTER><font
color="#000000"size="3">1234.56</font></TD>
<TD LOTUS_VALUE="ERR" ALIGN=RIGHT><font color="#ffffff"size="3">34.56</font></TD>
[snip snip]
Cheers
James
--
################################################################
# #
# A Thought on Perl Poetry and the Immortal JAPH #
# #
# I, require strict* and do not require warnings*. My answer #
# equals reference you unless answer equals 42. Question: If #
# defined, by this paradigm, do you do, the hacker foo? Now #
# join the data (why Fs & Os?), so the space or newline goes #
# Character evaluate: Reverse split null, then for each foo: #
# You ate foo, but I ate two. Answer -> Join with null, sort #
# the spots, and print it join the dots. Go now and exit, do #
# not die, else go to question and answer why? JAPH! (c)JADF #
# #
################################################################
I, require strict and do(not require warnings); my $answer = \$u
unless $answer == '42'; Question: if(defined by this_paradigm do
you_do_the_hacker_foo(??)){sub AUTOLOAD{$_=$now=join'the',<DATA>
;y?FO?01?; s.o|the| |\n..goe;s/(.{7})/(chr(eval'($u,$ate)=(0,1);
foreach $foo(reverse split "",$1){$u+=$ate*$foo;$but_I=$ate*=2;}
$$answer'))/eg;$_= join'',sort/(..)/g and print join'',/.(.)/go;
$now and exit, do(not die)}}else{goto Question and $answer;y???}
__DATA__
OOFFOOOOOFOO OFOO OOFFFOOOFFO FOOO FFOO OFFO
FFFOOFOOOFOF OFFFFOOF OFFFOOFOOOOO OFOO FOFO FFFF
FOOO FOOF OOFO FOOO OFOF OOOO FFOF OOOF
OFOF OOFO FFFO OFFF OOOO OFFO OOOF FFFO
OFFO FOFOOOFFOFFO FFFFFOOOFOFF OOFFFFOOOFFO FFOO
OFOF FOOFFOFOFOFF FFFOOFFOOFO FFFFFOOOOFOF OOOF
FFOO OOOF FFOO OFOO FFOO OFFF FOOO
FF OFOO FOOO OOOF FOFO OOFO OFFO
OOFFOFOO FFFO FOOO FOFO OOFO FFOO OOFO
FFOOOF OOOO OFFO FOOO OOFF OFOF FFFO
------------------------------
Date: Mon, 14 May 2001 03:50:03 +0200
From: "i-K@n Solutions" <i-Kan@GETRIDOFBalkanEnergyReview.com>
Subject: Net::SMTP problem
Message-Id: <3AFF39C9.43043514@GETRIDOFBalkanEnergyReview.com>
Hi!
I tried to write a script that does SMTP over POP3 and got it working on
my PC using ActiveState Perl.
I loaded it up to Hypermart and it only half worked - it stopped after
Net:POP3 and then bombed out with a 500 error.
I tried using a different SMTP - not provided by my ISP - and it worked
from the PC but not on Hypermart.
Here is my code and the error message.
Does any one have any idea?
================
#!/usr/local/bin/perl
use Net::POP3;
use Net::SMTP;
use strict;
# POP3
my $pop3host = "pop.mail.yahoo.com";
my $user = "whatever";
my $password = "password";
my $pop3 = Net::POP3->new($pop3host, Debug => 1,)
|| die("Can't connect to $pop3host. $!");
my $Number_Of_Messages = $pop3->login($user, $password);
die ("POP3 Auth failed. $!") unless (defined $Number_Of_Messages);
# SMTP
my $SMTP_Host = 'smtp.mail.yahoo.com';
my $account = 'mydomain.com';
my $accepted = 0;
my $smtp;
my $naptime = 10;
# sleep($naptime);
until ($accepted) {
eval {
$smtp = Net::SMTP->new( $SMTP_Host,
Helo => $account,
Debug => 1,
)
|| die "NO__CONNECTION";
}; ## eval
if ($@) {
if ($@ =~ /NO__CONNECTION/) {
# sleep($naptime);
next;
}
else { die $@;
} ## if ($@)
$accepted = 1;
} ## until
my $MailFrom = "whatever\@yahoo.com";
my $MailTo = "anything\@mydomain.com";
my $MailSubject = "SMTP over POP Trial";
$smtp->mail( $MailFrom );
$smtp->to( "$MailTo" );
# Start the mail
$smtp->data();
# Send the header.
$smtp->datasend("Subject: $MailSubject");
$smtp->datasend("\n");
# Send the message
# $smtp->datasend("Here are all the cool new links...\n\n");
# Send the termination string
$smtp->dataend();
$smtp->quit();
print "Content-type: text/html\n\n";
print "Done";
===============================
What is in the Error Log.
Net::POP3: Net::POP3(2.12)
Net::POP3: Net::Cmd(2.11)
Net::POP3: Exporter
Net::POP3: IO::Socket::INET
Net::POP3: IO::Socket(1.1603)
Net::POP3: IO::Handle(1.1504)
Net::POP3=GLOB(0x8134618)<<< +OK hello from popgate
Net::POP3=GLOB(0x8134618)>>> USER whoever
Net::POP3=GLOB(0x8134618)<<< +OK password required.
Net::POP3=GLOB(0x8134618)>>> PASS ....
Net::POP3=GLOB(0x8134618)<<< +OK maildrop ready, 0 messages (0 octets)
(6627 6291456)
==============================
When I run it on my PC, there are things like
Net::SMTP=GLOB(0x etc etc etc)<<< .etc etc etc
Kan
------------------------------
Date: Mon, 14 May 2001 11:41:17 +1000
From: James freeman <jfreeman@tassie.net.au>
Subject: Re: perl -c to file
Message-Id: <3AFF37BD.D982D7E2@tassie.net.au>
"Stéfan Sinclair" wrote:
> Dear all,
>
> Could someone please tell me how I can dump the results of a perl -c
> [filename] to a file in Unix?
>
> I've tried all sorts of combinations including the obvious:
>
> perl -c scriptname > results
>
> I think the problem is that the compiler somehow doesn't print its results
> to the standard output the way I'm used to, so my results file always ends
> up empty. I've noticed something of the same nature when I try a more/less
> with the piped results of a perl -c (since the screens can sometimes be very
> long) - but again, the standard out doesn't appear to function as I would
> expect.
>
> This is for a simple web-based script editor, so I don't think debugger
> approaches would be much use. I'm trying to determine whether or not a
> script will succeed before redirecting to it (so I can't just eval the
> script, and I want to run it alone, not as a module).
>
> As an intermediate perl/unix person, there may be something obvious that I'm
> missing.
>
> Thanks,
>
> Stéfan
Hi Stefan,
I posted almost exactly the same question on both clpmisc and clpmod a couple of
weeks ago (1 May 01). You will find it under the subject heading:
Capture output of perl -c myscript.pl
In the post I detailed all the code which does not work, the FAQ search etc.
There were a number of answers posted. Sadly none of these actually work on
WIN32 :-( As I have not had time to test them on my Linux box thay may well work
for you so check out this thread. If you have checked out the FAQ redirecting
STDERR you will have seen most of these answers already.
If you check out my original post you will find two practical workarounds that
will test a script for you. The second one is the best one - it effectively
simulates perl -c and captures the string syntax OK if it is or a null string if
it is broken. Forget the first one.
If you find something that actually works as we both obviously expect I would
love to see it.
Cheers
James
--
################################################################
# #
# A Thought on Perl Poetry and the Immortal JAPH #
# #
# I, require strict* and do not require warnings*. My answer #
# equals reference you unless answer equals 42. Question: If #
# defined, by this paradigm, do you do, the hacker foo? Now #
# join the data (why Fs & Os?), so the space or newline goes #
# Character evaluate: Reverse split null, then for each foo: #
# You ate foo, but I ate two. Answer -> Join with null, sort #
# the spots, and print it join the dots. Go now and exit, do #
# not die, else go to question and answer why? JAPH! (c)JADF #
# #
################################################################
I, require strict and do(not require warnings); my $answer = \$u
unless $answer == '42'; Question: if(defined by this_paradigm do
you_do_the_hacker_foo(??)){sub AUTOLOAD{$_=$now=join'the',<DATA>
;y?FO?01?; s.o|the| |\n..goe;s/(.{7})/(chr(eval'($u,$ate)=(0,1);
foreach $foo(reverse split "",$1){$u+=$ate*$foo;$but_I=$ate*=2;}
$$answer'))/eg;$_= join'',sort/(..)/g and print join'',/.(.)/go;
$now and exit, do(not die)}}else{goto Question and $answer;y???}
__DATA__
OOFFOOOOOFOO OFOO OOFFFOOOFFO FOOO FFOO OFFO
FFFOOFOOOFOF OFFFFOOF OFFFOOFOOOOO OFOO FOFO FFFF
FOOO FOOF OOFO FOOO OFOF OOOO FFOF OOOF
OFOF OOFO FFFO OFFF OOOO OFFO OOOF FFFO
OFFO FOFOOOFFOFFO FFFFFOOOFOFF OOFFFFOOOFFO FFOO
OFOF FOOFFOFOFOFF FFFOOFFOOFO FFFFFOOOOFOF OOOF
FFOO OOOF FFOO OFOO FFOO OFFF FOOO
FF OFOO FOOO OOOF FOFO OOFO OFFO
OOFFOFOO FFFO FOOO FOFO OOFO FFOO OOFO
FFOOOF OOOO OFFO FOOO OOFF OFOF FFFO
------------------------------
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 891
**************************************