[29387] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 631 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 7 16:10:12 2007

Date: Sat, 7 Jul 2007 13:09:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 7 Jul 2007     Volume: 11 Number: 631

Today's topics:
    Re: Certfication in AWK or SHell programming <uri@stemsystems.com>
    Re: DBIx::Simple variable interpolation problem <mritty@gmail.com>
        How to check a form's field and exit Perl program if it <louis_@n0Spam_.hemmi.us>
    Re: How to check a form's field and exit Perl program i <lambik@kieffer.nl>
    Re: How to check a form's field and exit Perl program i <spamtrap@dot-app.org>
    Re: How to check a form's field and exit Perl program i <jurgenex@hotmail.com>
    Re: How to check a form's field and exit Perl program i <louis_@n0Spam_.hemmi.us>
    Re: How to check a form's field and exit Perl program i <louis_@n0Spam_.hemmi.us>
    Re: How to check a form's field and exit Perl program i <louis_@n0Spam_.hemmi.us>
    Re: How to check a form's field and exit Perl program i <louis_@n0Spam_.hemmi.us>
    Re: How to check a form's field and exit Perl program i <tadmc@seesig.invalid>
    Re: How to check a form's field and exit Perl program i <lambik@kieffer.nl>
    Re: How to check a form's field and exit Perl program i <noreply@gunnar.cc>
    Re: In windows, start default app associated with file  <stoupa@practisoft.cz>
    Re: In windows, start default app associated with file  <lambik@kieffer.nl>
    Re: re-lurking <uri@stemsystems.com>
    Re: re-lurking <uri@stemsystems.com>
    Re: Trying to write a log function <hjp-usenet2@hjp.at>
    Re: Trying to write a log function <hjp-usenet2@hjp.at>
    Re: validating a group of variables <mritty@gmail.com>
    Re: validating a group of variables <stoupa@practisoft.cz>
    Re: validating a group of variables <rvtol+news@isolution.nl>
    Re: validating a group of variables <noreply@gunnar.cc>
    Re: validating a group of variables <spamtrap@dot-app.org>
    Re: validating a group of variables <rvtol+news@isolution.nl>
    Re: validating a group of variables <jwkenne@attglobal.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sat, 07 Jul 2007 17:56:46 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Certfication in AWK or SHell programming
Message-Id: <x7wsxc9jxt.fsf@mail.sysarch.com>

>>>>> "e" == ehabaziz2001  <ehabaziz2001@gmail.com> writes:

  e> can I have any kind of certfifcation in Awk and SED and if the answer
  e> is NO What is the nearest certfication to SED,AWK and even any
  e> certfifcation to shell programming?

i will issue you a certificate if you pay me! it probably will be as
useful as any other you could get (which is not much) and i expect i
would charge less and make sure you know more. :)

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


------------------------------

Date: Sat, 07 Jul 2007 06:31:40 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: DBIx::Simple variable interpolation problem
Message-Id: <1183815100.319552.9780@q75g2000hsh.googlegroups.com>

On Jul 7, 6:38 am, Justin C <justin.0...@purestblue.com> wrote:
> In article <1183728033.340188.296...@n2g2000hse.googlegroups.com>, Paul Lalli wrote:
> >>         my $query = $dataSource->query('SELECT key FROM
> >>         prospect WHERE ? ~* ?', $field, $sc) ;
>
> > Like I said, you can't use placeholders for column names.  
> > Just put the columnname directly into your SQL:
> > my $query = $dataSource->query("SELECT key FROM prospect WHERE
> > $field = ?", $sc);
>
> Oooh, no placeholders, but vars/$scalars are OK?

A string is a string is a string.  The query() method has no way of
knowing how that string is being created.  The Perl interpreter sees a
double-quoted string, searches the string for any variables,
interpolates any it finds, and then passes the string to the query()
method.

> That's good news... I see you've changed the quote from singles
> to doubles, vars not being interpreted inside singles

Correct.  But query() doesn't have any way of knowing what delimiters
were being used, or if there were any variables interpolated into the
string.  By the time the argument is passed, it's simply "a string".

> - I suppose my not having read DBI.pm docs (or possibly my being
> green) I didn't think of that... I did wonder about putting the
> var inside the quotes but realised it wouldn't work because they
> were single, not double... never occurred to me that I might be
> able to use doubles! [duh!]

The only difference in Perl between single-quoted and double-quoted
strings is interpolation.  Anywhere you can use single-quoted strings,
you can use double-quoted strings.  The only difference is that Perl
will search the double-quoted strings for any variables or escape
sequences.

Paul Lalli



------------------------------

Date: Sat, 07 Jul 2007 13:08:10 -0500
From: Gdareos <louis_@n0Spam_.hemmi.us>
Subject: How to check a form's field and exit Perl program if it has a value?
Message-Id: <g2lv835e6mkc7gut2pffqsib72flt5ta2c@4ax.com>

I know just a little about Perl. I'd like to add a statement to
Formmail.pl (from Matt's Script archive). 

I have a hidden field on an input form

<input name="bot_detector" type = "hidden" value="">

I think that if  the "bot_detector" field  has any value other than
"", I'd like to stop the Perl Script and return to the html page. 

We've been bombarded by Eastern European bots triggering bogus contact
form entries. I spent hours getting the PERL script to work for the
last couple of years, so I've not spent any time with PERL in all that
time, and never use it otherwise. Since we have many fields on this
contact form, I don't want to spend the time to learn PHP and redo the
whole thing. 

Someone posted a PHP example, but I don't know how to put it in PERL
terms.

PHP
if($_POST['bot_detector']) {echo 'Tastes Like Spam!';} else {. . .
send email. . .]

Thanks very much for any help!

George


------------------------------

Date: Sat, 7 Jul 2007 20:22:45 +0200
From: "Lambik" <lambik@kieffer.nl>
Subject: Re: How to check a form's field and exit Perl program if it has a value?
Message-Id: <468fd9a9$0$37723$5fc3050@dreader2.news.tiscali.nl>

"Gdareos" <louis_@n0Spam_.hemmi.us> wrote in message
news:g2lv835e6mkc7gut2pffqsib72flt5ta2c@4ax.com...
> I know just a little about Perl. I'd like to add a statement to
> Formmail.pl (from Matt's Script archive).

So you know nothing of Perl and you want us to write you a script?

>
> I have a hidden field on an input form
>
> <input name="bot_detector" type = "hidden" value="">

Sounds like that doesn't change much. So it is ALWAYS ""


> I think that if  the "bot_detector" field  has any value other than
> "", I'd like to stop the Perl Script and return to the html page.
>
> We've been bombarded by Eastern European bots triggering bogus contact
> form entries. I spent hours getting the PERL script to work for the

that is because you don't know how to write a program.

> last couple of years, so I've not spent any time with PERL in all that
> time, and never use it otherwise. Since we have many fields on this
> contact form, I don't want to spend the time to learn PHP and redo the
> whole thing.

Again, so you want us to do it

> Someone posted a PHP example, but I don't know how to put it in PERL
> terms.
>
> PHP
> if($_POST['bot_detector']) {echo 'Tastes Like Spam!';} else {. . .
> send email. . .]
>

Won't help you much since you don't know how to write a Perl script, but
here it goes:

use strict;
use warnings;
use CGI qw/:standard/;

my $query = new CGI;
if ($query->param('bot_detector')) {
 print 'Tastes Like Spam!';
 exit;
}




------------------------------

Date: Sat, 07 Jul 2007 14:22:54 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: How to check a form's field and exit Perl program if it has a value?
Message-Id: <m2wsxcul8h.fsf@dot-app.org>

Gdareos <louis_@n0Spam_.hemmi.us> writes:

> I know just a little about Perl. I'd like to add a statement to
> Formmail.pl (from Matt's Script archive). 

MSA is an archive of quite possibly the worst Perl coding on the planet.
Don't bother trying to fix it - it's hopeless.

Far better alternatives can be found at NMS:

    <http://nms-cgi.sourceforge.net/>

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


------------------------------

Date: Sat, 07 Jul 2007 18:26:37 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: How to check a form's field and exit Perl program if it has a value?
Message-Id: <xVQji.2411$ZO4.2014@trndny05>

Gdareos wrote:
> We've been bombarded by Eastern European bots triggering bogus contact
> form entries.

Somehow you must have missed the current thread "validating a group of 
variables".

jue 




------------------------------

Date: Sat, 07 Jul 2007 13:31:54 -0500
From: Gdareos <louis_@n0Spam_.hemmi.us>
Subject: Re: How to check a form's field and exit Perl program if it has a value?
Message-Id: <4kmv83hq4qjtotkpg7ei8mjiug8g7bm840@4ax.com>

WOW! That was fast, indeed. 

I apologize for appearing  lazy, it just looked so much like just a
few moments from someone familiar with PERL would be more efficient
than having to learn from scratch. It seems I have to become an expert
on anything I want to accomplish.

The script I modified just was working so well for so long so I didn't
have any real incentive to become an expert, when it's not a core job
requirement. 

The logic for the bot_detector field, as I understand it, is that the
bots fill in all fields, hidden or not, so if there's a value, then
it's not from a legitimate user.

Seems to be a pretty nifty strategy if the premise is true.

Thanks for your response, and I'll try to implement over this weekend
:) 




On Sat, 7 Jul 2007 20:22:45 +0200, "Lambik" <lambik@kieffer.nl> wrote:

>"Gdareos" <louis_@n0Spam_.hemmi.us> wrote in message
>news:g2lv835e6mkc7gut2pffqsib72flt5ta2c@4ax.com...
>> I know just a little about Perl. I'd like to add a statement to
>> Formmail.pl (from Matt's Script archive).
>
>So you know nothing of Perl and you want us to write you a script?
>
>>
>> I have a hidden field on an input form
>>
>> <input name="bot_detector" type = "hidden" value="">
>
>Sounds like that doesn't change much. So it is ALWAYS ""
>
>
>> I think that if  the "bot_detector" field  has any value other than
>> "", I'd like to stop the Perl Script and return to the html page.
>>
>> We've been bombarded by Eastern European bots triggering bogus contact
>> form entries. I spent hours getting the PERL script to work for the
>
>that is because you don't know how to write a program.
>
>> last couple of years, so I've not spent any time with PERL in all that
>> time, and never use it otherwise. Since we have many fields on this
>> contact form, I don't want to spend the time to learn PHP and redo the
>> whole thing.
>
>Again, so you want us to do it
>
>> Someone posted a PHP example, but I don't know how to put it in PERL
>> terms.
>>
>> PHP
>> if($_POST['bot_detector']) {echo 'Tastes Like Spam!';} else {. . .
>> send email. . .]
>>
>
>Won't help you much since you don't know how to write a Perl script, but
>here it goes:
>
>use strict;
>use warnings;
>use CGI qw/:standard/;
>
>my $query = new CGI;
>if ($query->param('bot_detector')) {
> print 'Tastes Like Spam!';
> exit;
>}
>


------------------------------

Date: Sat, 07 Jul 2007 13:36:03 -0500
From: Gdareos <louis_@n0Spam_.hemmi.us>
Subject: Re: How to check a form's field and exit Perl program if it has a value?
Message-Id: <f7nv83df6kfbpvie4urn661peav37q9bl4@4ax.com>

I did. That's not a search I used :) 

Thanks - will look for this.

On Sat, 07 Jul 2007 18:26:37 GMT, "Jürgen Exner"
<jurgenex@hotmail.com> wrote:

>Gdareos wrote:
>> We've been bombarded by Eastern European bots triggering bogus contact
>> form entries.
>
>Somehow you must have missed the current thread "validating a group of 
>variables".
>
>jue 
>


------------------------------

Date: Sat, 07 Jul 2007 13:38:08 -0500
From: Gdareos <louis_@n0Spam_.hemmi.us>
Subject: Re: How to check a form's field and exit Perl program if it has a value?
Message-Id: <janv831qrttbi1ve89gsiugjvkgj0pmidd@4ax.com>

This looks good if I can't figure out Lambik's suggestion. 

Thanks. this looks pretty good from NMS.

"nms FormMail is a drop-in replacement for Matt Wright's FormMail
script. It converts an HTML form submission to an email message."


On Sat, 07 Jul 2007 14:22:54 -0400, Sherm Pendley
<spamtrap@dot-app.org> wrote:

>Gdareos <louis_@n0Spam_.hemmi.us> writes:
>
>> I know just a little about Perl. I'd like to add a statement to
>> Formmail.pl (from Matt's Script archive). 
>
>MSA is an archive of quite possibly the worst Perl coding on the planet.
>Don't bother trying to fix it - it's hopeless.
>
>Far better alternatives can be found at NMS:
>
>    <http://nms-cgi.sourceforge.net/>
>
>sherm--


------------------------------

Date: Sat, 07 Jul 2007 13:40:09 -0500
From: Gdareos <louis_@n0Spam_.hemmi.us>
Subject: Re: How to check a form's field and exit Perl program if it has a value?
Message-Id: <2fnv835ru2rujqsdatbikd0nm394h1jpmb@4ax.com>

Found it -- thanks very much!

"We have been suffering much lately from users abusing our Website
forms with . . . "


On Sat, 07 Jul 2007 18:26:37 GMT, "Jürgen Exner"
<jurgenex@hotmail.com> wrote:

>Gdareos wrote:
>> We've been bombarded by Eastern European bots triggering bogus contact
>> form entries.
>
>Somehow you must have missed the current thread "validating a group of 
>variables".
>
>jue 
>


------------------------------

Date: Sat, 7 Jul 2007 14:04:05 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: How to check a form's field and exit Perl program if it has a value?
Message-Id: <slrnf8vot5.qj6.tadmc@tadmc30.sbcglobal.net>


[ Please do not top-post! ]


Gdareos <louis_@n0Spam_.hemmi.us> wrote:
> On Sat, 07 Jul 2007 14:22:54 -0400, Sherm Pendley
><spamtrap@dot-app.org> wrote:
>
>>Gdareos <louis_@n0Spam_.hemmi.us> writes:
>>
>>> I know just a little about Perl. I'd like to add a statement to
>>> Formmail.pl (from Matt's Script archive). 
>>
>>MSA is an archive of quite possibly the worst Perl coding on the planet.
>>Don't bother trying to fix it - it's hopeless.


> This looks good if I can't figure out Lambik's suggestion. 


It looks good even if you *can* figure out Lambik's suggestion.

There are cracker programs that spider the 'net looking
for Formmail.pl so they can take over machines.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


------------------------------

Date: Sat, 7 Jul 2007 21:39:58 +0200
From: "Lambik" <lambik@kieffer.nl>
Subject: Re: How to check a form's field and exit Perl program if it has a value?
Message-Id: <468febc2$0$37741$5fc3050@dreader2.news.tiscali.nl>

"Tad McClellan" <tadmc@seesig.invalid> wrote in message
news:slrnf8vot5.qj6.tadmc@tadmc30.sbcglobal.net...

> It looks good even if you *can* figure out Lambik's suggestion.
>
> There are cracker programs that spider the 'net looking
> for Formmail.pl so they can take over machines.


It is easy to sound condescending and that is not my intention, but I'm
always surprised about the skills of the people creating internet pages
nowadays.  That is one of the reasons I don't work in the IT anymore. If you
go to a doctor do you expect him to Google or do you expect him to know the
answer. Apparently there is no need for skills in programming anymore. A
week learning VB usually is enough.




------------------------------

Date: Sat, 07 Jul 2007 20:52:57 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to check a form's field and exit Perl program if it has a value?
Message-Id: <5fa5u7F3ajocrU1@mid.individual.net>

Gdareos wrote:
> I know just a little about Perl. I'd like to add a statement to
> Formmail.pl (from Matt's Script archive).

Then you should check out these alternatives: 
http://nms-cgi.sourceforge.net/scripts.shtml

> I have a hidden field on an input form
> 
> <input name="bot_detector" type = "hidden" value="">
> 
> I think that if  the "bot_detector" field  has any value other than
> "", I'd like to stop the Perl Script and return to the html page.

<snip>

> Someone posted a PHP example, but I don't know how to put it in PERL
> terms.
> 
> PHP
> if($_POST['bot_detector']) {echo 'Tastes Like Spam!';} else {. . .
> send email. . .]

     if ( $Form{'bot_detector'} ) {
         print "Content-type: text/plain\n\n";
         print "Tastes Like Spam!\n";
         exit 1;
     }

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: Sat, 7 Jul 2007 16:55:09 +0200
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: In windows, start default app associated with file type
Message-Id: <f6oalh$n27$1@ns.felk.cvut.cz>

Lambik wrote:
> "Petr Vileta" <stoupa@practisoft.cz> wrote in message
>>> exec "rundll32.exe url.dll, FileProtocolHandler my.pdf "
>> Can you explain me what is the "FileProtocolHandler" ? Please wrote 2
>> examples for my.pdf on web and on local disk.
>
> You're kidding, right? Have you even tried? my.pdf is a local file.
> exec "rundll32.exe url.dll, FileProtocolHandler
> http://tiger.la.asu.edu/Quick_Ref/perl_quickref.pdf" opens from the
> web. Sounds logical right?
Hmm, I tried this and I found that "FileProtocolHandler" is the constant 
defined somewhere in url.dll library. Right?
-- 

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail 
from another non-spammer site please.)





------------------------------

Date: Sat, 7 Jul 2007 20:10:01 +0200
From: "Lambik" <lambik@kieffer.nl>
Subject: Re: In windows, start default app associated with file type
Message-Id: <468fd6ab$0$37744$5fc3050@dreader2.news.tiscali.nl>

"Petr Vileta" <stoupa@practisoft.cz> wrote in message
news:f6oalh$n27$1@ns.felk.cvut.cz...
> Hmm, I tried this and I found that "FileProtocolHandler" is the constant
> defined somewhere in url.dll library. Right?
> -- 

Depends on what you call "constant". Basicly, a DLL is what we in Perl call
a package. In contains a number of subroutines. FileProtocolHandler is such
a subroutine. You call the program rundll.exe and ask it to open a package
called url.dll and run its subroutine FileProtocolHandler with given
arguments. Much as you would do in Perl like:

perl -MURL.dll -e "FileProtocolHandler (\"
http://tiger.la.asu.edu/Quick_Ref/perl_quickref.pdf\")"

of course this will not work but you get my drift.




------------------------------

Date: Sat, 07 Jul 2007 17:51:28 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: re-lurking
Message-Id: <x73b00ayqn.fsf@mail.sysarch.com>

>>>>> "WW" == Wade Ward <invalid@invalid.nyet> writes:

  WW> my $USER   = 'zaxfuuq@comcast.net';
  WW> my $PASSWD = '';
  WW> my $SERVER = 'anything';        # aka news.comcast.giganews.com

why isn't that set to a proper server name?? one that you have access
to? others have already told you what the comcast server's name is. THIS
IS YOUR PRIMARY BUG. without a legit server you get nowhere.

  WW> my $nntp = Net::NNTP->new($SERVER, { Debug => 1} );

the docs say options are a key/value list and not a hash ref. did you
read the docs and examples??


	new ( [ HOST ] [, OPTIONS ])

    This is the constructor for a new Net::NNTP object. HOST is the name
    of the remote host to which a NNTP connection is required. If not
    given then it may be passed as the Host option described below. If
    no host is passed then two environment variables are checked, first
    NNTPSERVER then NEWSHOST, then Net::Config is checked, and if a host
    is not found then news is used.

++++++++++++++++++
READ THIS CAREFULLY

    OPTIONS are passed in a hash like fashion, using key and value
    pairs. Possible options are:
++++++++++++++++++

    Host - NNTP host to connect to. It may be a single scalar, as
    defined for the PeerAddr option in IO::Socket::INET, or a reference
    to an array with hosts to try in turn. The "host" method will return
    the value which was used to connect to the host.


  WW> print "new($SERVER) returned $nntp\n";

WHY ARE YOU NOT CHECKING IF new() Succeeded? printing it is useless as
you just continue on even if it fails. get EACH step working before you
proceed. you must get some object back that isn't undef. the rest of the
code is moot before you do this correctly. 


your whining about this being hard and not easy is offtarget. you have
never done the correct baby steps. you keep using the wrong news server
names and user name. you can post that and edit out your password for
security. i could get this working (as others have shown already) in
minutes. the module works and is stable and easy to use and well
documented. the fault must lie elsewhere (use a mirror to find it).

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


------------------------------

Date: Sat, 07 Jul 2007 17:52:49 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: re-lurking
Message-Id: <x71wfkayoe.fsf@mail.sysarch.com>

>>>>> "MD" == Michele Dondi <bik.mido@tiscalinet.it> writes:

  MD> SCENARIO 2:

  MD> Despite Uri's comment, I *don't* think that downloading articles from
  MD> Usenet would qualify as the first baby step after hello world. But it
  MD> is feasible. Of course you should use a suitable module, like
  MD> Net::NNTP, which you've been pointed to. Then you should read the
  MD> module's documentation over and over again till you understand every
  MD> single bit of syntax and semantics for the each given "element" of it.
  MD> If you can't, then again, ask. Start with incremental steps. E.g.
  MD> print the server's time stamp, then a list of available articles
  MD> before attempting to download them, and so on. Of course if you really
  MD> are only beyond hello world, there are a lot of things you're deemed
  MD> not to understand: e.g. some methods return *arrayrefs*. Then you'll
  MD> need to read about *references* either in your book or in

and he didn't even do that. i decided to look at the docs and noticed
immediately a bug in his code. options are a key/value LIST and not a
hash ref. he had a hash ref last time i looked.

also he never seems to use the proper news server hostname for
comcast. someone who won't listen to good advice is not someone wasting
more time on.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


------------------------------

Date: Sat, 7 Jul 2007 20:33:21 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Trying to write a log function
Message-Id: <slrnf8vn3h.435.hjp-usenet2@zeno.hjp.at>

On 2007-07-04 11:23, Tim Southerwood <ts@dionic.net> wrote:
>
> Opening and closing the file on every call to Log() is expensive. One
> usually opens it once and then keeps the file handle around.

Yup.


> In this case, it might be considered "good manners" to have the program
> respond to SIGHUP to close and reopen the log file for the benefit of
> logrotation, though logrotate can work around this if necessary.

Another way is to switch log files automatically from the logging
routine. A handy way to do this is to include a timestamp (e.g. the
current day) in the log file name and for every entry (or at other
convenient moments such as when a new client connects) check if the log
file name has changed:


{
    my $log_filename_template = "/var/log/whatever/%Y-%m-%d";
    my $log_filename = '';
    my $log_fh;

    sub log {
	my ($msg) = @_;
	my @lt = localtime();
	my $ts = strftime("%Y-%m-%dT%H:%M:%S%z", @lt);
	my $fn = strftime($log_filename_template, @lt);
	if ($fn ne $log_filename) {
	    if ($log_fh) {
		close($log_fh) or die "error closing $log_filename: $!";
	    }
	    $log_filename = $fn;
	    open($log_fh, ">>", $log_filename) or die "error opening $log_filename: $!";
	    $log_fh->autoflush(1);
	}
	$log_fh->print("$ts $msg\n") or die "error writing $log_filename: $!";
    }
}

You still need a cronjob to compress and/or delete old logfiles.

	hp


-- 
   _  | Peter J. Holzer    | I know I'd be respectful of a pirate 
|_|_) | Sysadmin WSR       | with an emu on his shoulder.
| |   | hjp@hjp.at         |
__/   | http://www.hjp.at/ |	-- Sam in "Freefall"


------------------------------

Date: Sat, 7 Jul 2007 20:45:16 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Trying to write a log function
Message-Id: <slrnf8vnps.435.hjp-usenet2@zeno.hjp.at>

On 2007-07-04 11:26, Jrgen Exner <jurgenex@hotmail.com> wrote:
> Tim Southerwood wrote:
>> Opening and closing the file on every call to Log() is expensive.
>
> True.
>
>> One usually opens it once and then keeps the file handle around.
>
> Depends. If you want to capture the last breath of your program before it 
> dies an untimely death then you don't want to risk loosing its last words in 
> an unsaved buffer.

You should generally turn autoflush on on log files. Apart from the
reason you just mentioned there are two others:

1) If your program only prints log entries only infrequently, it may
   take a long time until the (typically 4kB or 8kB) buffer fills up. 
   Normally you want every log message in the log immediately, not a
   bunch of messages every few hours.

2) Buffers usually have a fixed size, so the blocks written to the log
   file will not start and end at line boundaries. If you have several
   processes writing to the same log file lines will be mixed. If you
   flush after every line that can't happen (at least on Unix, the
   kernel makes sure that a single write on a file in append mode is
   written atomically). For the same reason you should write the whole
   message with a single print call.

	hp


-- 
   _  | Peter J. Holzer    | I know I'd be respectful of a pirate 
|_|_) | Sysadmin WSR       | with an emu on his shoulder.
| |   | hjp@hjp.at         |
__/   | http://www.hjp.at/ |	-- Sam in "Freefall"


------------------------------

Date: Sat, 07 Jul 2007 08:26:39 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: validating a group of variables
Message-Id: <1183821999.084724.214780@q75g2000hsh.googlegroups.com>

On Jul 6, 7:13 pm, "Robert Valcourt"
<webmas...@know.spam.customfitonline.com> wrote:
> Hello,
>
> We have been suffering much lately from users abusing our
> Website forms with Spam. I have evaluated most of the spam
> submissions and im trying to modify my custom form-to-email perl
> processor to check for common spam submission and reject them.
> While this is not hard, im trying to streamline the scripts
> efficiency. Below is an example:
>
> #!/usr/bin/perl
>
> use lib '/usr/local/psa/home/vhosts/mybizdomain.com/cgi-bin/lib/';
> use CGI qw(:standard);
> use CGI::Carp qw(fatalsToBrowser);
> use Mail::Sendmail;
> use strict;
>
> my $fullname = param('fullname');
> my $emailaddy = param('emailaddy');
> my $phone = param('phone');
> my $company = param('company');
> my $website = param('website');
> my $completion = param('completion');
>
> spamattempt() if $fullname =~ /viagra/i;
> spamattempt() if $emailaddy =~ /viagra/i;
> spamattempt() if $phone =~ /viagra/i;
> spamattempt() if $fullname =~ /\@/;
>
> The real script is much longer but you get the idea. Its
> checking each defined variable for a spam match and then
> performing the spamattempt subroutine if matched. I would like
> to know if there is a way to check ALL variables against a single
> match. See example (not real perl cod):
>
> spamattempt() if $ANYVARIBALE =~ /viagra/i;


use List::MoreUtils qw/any/;
spamattempt() if any { /viagra/i } ($fullname, $emailaddy, $phone);

(Not that I think this is the best way to solve your actual problem -
it's just an answer to your actual question).

Paul Lalli



------------------------------

Date: Sat, 7 Jul 2007 17:13:58 +0200
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: validating a group of variables
Message-Id: <f6oalh$n27$2@ns.felk.cvut.cz>

Mumia W. wrote:
> On 07/07/2007 12:26 AM, Petr Vileta wrote:
>> Robert Valcourt wrote:
>>> Hello,
>>>
>>> We have been suffering much lately from users abusing our Website
>>> forms with Spam. I have evaluated most of the spam submissions and
>>> im
>>
>> The best way is to implement CAPTCHA into your script.
>
> No it is not. Please read Gunnar's message on how to stop blog
> spammers without using captchas.
>
> Captchas are evil. I'm not even blind, and I can barely see the capcha
> letters most of the time.
>
Captcha is a good idea ;-) I wrote my own "micro" version where I used not 
distorded images on white background and I reduced spammers on my webpage 
aproximately from 100 spams per day to 3 spams per month. Generalities of 
spam is generated by robots. How many robots use Captcha recognition? The 
answer is "None or few only" :-)
Other way to avoid spam is to use members registration. When somebody want 
to submit message then he/she must login with password. If some member start 
sending spam then you can simple disable his/her account.
These ways is better then trying to find spam word. What to find?
Viagra
V.i.a.g.r.a
Wiagra
Viaqra
Vi@gr@
V i a g r a
Here is too many ways how to make spam word readable for human but 
unfindable for program.
-- 

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail 
from another non-spammer site please.)





------------------------------

Date: Sat, 7 Jul 2007 17:29:06 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: validating a group of variables
Message-Id: <f6oijt.1gk.1@news.isolution.nl>

Mumia W. schreef:
> Dr.Ruud:
>> Mumia W.:

>>> spamattempt() if join('',values %pmhash) =~ /viagra/i;
>>
>> So if one of the values ends on 'via', and the next starts with
>> 'gra', it should match?
>
> Whoa! That's not so good. I need to make that more robust probably:
>
> use CGI ':cgi-lib'
> my %pmhash = Vars;
> spamattempt() if join("\0",values %pmhash) =~ /viagra/i;
>
> Thanks.

I think the same error was in Tad's code, the concatenation of the
params().

-- 
Affijn, Ruud

"Gewoon is een tijger."



------------------------------

Date: Sat, 07 Jul 2007 19:14:07 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: validating a group of variables
Message-Id: <5fa04uF3c5bloU1@mid.individual.net>

Petr Vileta wrote:
> Mumia W. wrote:
>> On 07/07/2007 12:26 AM, Petr Vileta wrote:
>>> Robert Valcourt wrote:
>>>> We have been suffering much lately from users abusing our Website
>>>> forms with Spam. I have evaluated most of the spam submissions and
>>>> im
>>>
>>> The best way is to implement CAPTCHA into your script.
>>
>> No it is not. Please read Gunnar's message on how to stop blog
>> spammers without using captchas.
>>
>> Captchas are evil. I'm not even blind, and I can barely see the capcha
>> letters most of the time.
>
> Captcha is a good idea ;-) I wrote my own "micro" version where I used 
> not distorded images on white background and I reduced spammers on my 
> webpage aproximately from 100 spams per day to 3 spams per month. 
> Generalities of spam is generated by robots. How many robots use Captcha 
> recognition? The answer is "None or few only" :-)

So CAPTCHA works. Nobody said it doesn't. Nevertheless it's 
inconvenient, even without distortion.

> Other way to avoid spam is to use members registration. When somebody 
> want to submit message then he/she must login with password. If some 
> member start sending spam then you can simple disable his/her account.

Some robots register themselves as members...

> These ways is better then trying to find spam word.

True, but again there are other methods. Remember this thread?
http://groups.google.com/group/comp.lang.perl.misc/browse_frm/thread/a83a344631121bc2

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: Sat, 07 Jul 2007 13:30:44 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: validating a group of variables
Message-Id: <m27ipcw27v.fsf@dot-app.org>

"Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net> writes:

> Captchas are evil. I'm not even blind, and I can barely see the capcha
> letters most of the time.
>
> Every year since that braindamage was introduced, the captchas have
> gotten more and more unreadable.

Because automated OCR has been getting better and better at deciphering
them automatically. It's an arms race, with the people on the CAPTCHA side
apparently not very interested in what their users think.

> What's next? Random pixels thrown
> onto the screen that must be interpreted according to some secret,
> hidden language?

Shhh! Don't give them any ideas... :-)

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


------------------------------

Date: Sat, 7 Jul 2007 19:22:48 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: validating a group of variables
Message-Id: <f6op7g.no.1@news.isolution.nl>

Paul Lalli schreef:

> spamattempt() if any { /viagra/i } ($fullname, $emailaddy, $phone);


You could put grep where any is, but grep is not shortcutting.

Example application:

#!/usr/bin/perl
  use strict;
  use warnings;

  use List::MoreUtils qw/any/;

  my $debug = 1;

  sub spamattempt {
      print "\nspam attempt: ", $_[0] || '?', "\n\n";
  }

  my %pattern =
  ( a => '[aA4]'
  , g => '[gG9]'
  , i => '[iIl1]'
  , r => '[rR]'
  , s => '[sS5]'
  , v => '(?:[vV]|\\/)'
  );
  for my $k ('a'..'z') {
    $pattern{$k} = "[$k\U$k]" if not exists $pattern{$k};
  }
  # double the backslashes
  $pattern{$_} =~ s/(\\)/$1$1/g for keys %pattern;

  for my $k (qw(viagra cialis)) {
    my @c = split //, $k;
    my $p = '';
    for my $c (@c) {
      $p .= $pattern{$c};
    }
    $pattern{$k} = $p;
  }

  $debug and print "$_ => $pattern{$_}\n" for sort keys %pattern;


  my ($fullname, $emailaddy, $phone) = qw(ruud needs.\\/1AGRA pronto);

  print "$_\n" for '', $fullname, $emailaddy, $phone;

  my $p;
  spamattempt($p) if any {/($pattern{viagra})/ and $p = $1}
                         ($fullname, $emailaddy, $phone);

-- 
Affijn, Ruud

"Gewoon is een tijger."


------------------------------

Date: Sat, 07 Jul 2007 13:52:38 -0400
From: "John W. Kennedy" <jwkenne@attglobal.net>
Subject: Re: validating a group of variables
Message-Id: <GpQji.501$RA6.242@newsfe12.lga>

Jürgen Exner wrote:
> If you want to stop spam being sent from your web site then you have to lock 
> it down and allow mail submissions only from authenticated users.
> Or at least require a "Please enter the text that you are seeing in this 
> picture" for every individual mail submission. Yes, they are annoying. 
> Unfortunately in real live they are the lesser evil.

I have had great success with not including the submit button in the 
HTML, instead creating it from JavaScript.

-- 
John W. Kennedy
Read the remains of Shakespeare's lost play, now annotated!
http://pws.prserv.net/jwkennedy/Double%20Falshood/index.html


------------------------------

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V11 Issue 631
**************************************


home help back first fref pref prev next nref lref last post