[29081] in Perl-Users-Digest
Perl-Users Digest, Issue: 325 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 11 21:09:59 2007
Date: Wed, 11 Apr 2007 18:09:08 -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 Wed, 11 Apr 2007 Volume: 11 Number: 325
Today's topics:
Continuous communication between user, CGI script and s <robinp.la@gmail.com>
Re: Continuous communication between user, CGI script a <spamtrap@dot-app.org>
How to interchange a handle and a scalar? <bcc@nospam.net>
Re: How to interchange a handle and a scalar? xhoster@gmail.com
Re: How to interchange a handle and a scalar? <spamtrap@dot-app.org>
Re: My script to download YouTube videos (critique want <purlgurl@purlgurl.net>
Re: My script to download YouTube videos (critique want <purlgurl@purlgurl.net>
Re: My script to download YouTube videos (critique want <bik.mido@tiscalinet.it>
Re: My script to download YouTube videos (critique want <bik.mido@tiscalinet.it>
Re: My script to download YouTube videos (critique want <bik.mido@tiscalinet.it>
Re: My script to download YouTube videos (critique want <ignoramus13850@NOSPAM.13850.invalid>
Re: My script to download YouTube videos (critique want <tadmc@augustmail.com>
Re: My script to download YouTube videos (critique want <tadmc@augustmail.com>
Re: Script to know who clicked a link? <bik.mido@tiscalinet.it>
Re: Script to know who clicked a link? <bik.mido@tiscalinet.it>
Re: Toggle between hot filehandles question usenet@DavidFilmer.com
Re: Toggle between hot filehandles question <awkster@yahoo.com>
Re: Toggle between hot filehandles question <rvtol+news@isolution.nl>
Re: Toggle between hot filehandles question <bik.mido@tiscalinet.it>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 11 Apr 2007 15:22:18 -0700
From: "robinp.la@gmail.com" <robinp.la@gmail.com>
Subject: Continuous communication between user, CGI script and server
Message-Id: <1176330138.819328.64530@e65g2000hsc.googlegroups.com>
I am really new to CGI programming so excuse me if this is posted in
the wrong group with the wrong lingo etc. Maybe someone can at least
help me in the right direction.
So I have managed to write a CGI script that processes the user's
unputs and then spits back HTML code to the user. Pretty straight
forward. What if I want the user to be able to send data continuously
to my CGI script? Like what if the user drag his mouse around and I
want to process that data every 5 seconds or something. How do I do
that?
If this doesn't make sense, please ask me questions.
Thanks,
Robin
------------------------------
Date: Wed, 11 Apr 2007 18:32:04 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Continuous communication between user, CGI script and server
Message-Id: <m2lkgymtjv.fsf@local.wv-www.com>
"robinp.la@gmail.com" <robinp.la@gmail.com> writes:
> So I have managed to write a CGI script that processes the user's
> unputs and then spits back HTML code to the user. Pretty straight
> forward. What if I want the user to be able to send data continuously
> to my CGI script? Like what if the user drag his mouse around and I
> want to process that data every 5 seconds or something. How do I do
> that?
Have a look at AJAX. In a nutshell, you have some JavaScript in your page
that periodically looks at the position of the mouse, and submits a request
to your server-side app. Your server-side app will return either XML or
JSON formatted data, which the JavaScript will then use to update the page
by manipulating its DOM.
This is what Google Maps uses, for instance, when you drag a map around in
its viewport.
Not much to do with Perl though. The server side is pretty bog-standard,
aside from returning XML or JSON instead of HTML. The hairy stuff is all on
the client - you should ask about that in a JavaScript group. Or just google
for "AJAX tutorial" to get started.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Wed, 11 Apr 2007 16:45:07 -0700
From: Bryan <bcc@nospam.net>
Subject: How to interchange a handle and a scalar?
Message-Id: <1qeTh.3901$H_5.2894@newssvr23.news.prodigy.net>
I am using a perl package (Data::Table) that has a function called
fromTSV and takes a name or a handler to a TSV file.
But I am generating a TSV file in memory from an XML/XSLT transform. I
want to pop this into the Data::Table stuff, but would prefer not to
dump it to disk and then read it back in.
To do this I need to give fromTSV what it expects, right? So I would
need to provide the function with a handler to a string (?).
Or maybe this is just impossible and I should rewrite fromTSV to suit my
needs?
Any hints?
Thanks,
B
------------------------------
Date: 12 Apr 2007 00:15:42 GMT
From: xhoster@gmail.com
Subject: Re: How to interchange a handle and a scalar?
Message-Id: <20070411201545.376$Iz@newsreader.com>
Bryan <bcc@nospam.net> wrote:
> I am using a perl package (Data::Table) that has a function called
> fromTSV and takes a name or a handler to a TSV file.
>
> But I am generating a TSV file in memory from an XML/XSLT transform. I
> want to pop this into the Data::Table stuff, but would prefer not to
> dump it to disk and then read it back in.
>
> To do this I need to give fromTSV what it expects, right? So I would
> need to provide the function with a handler to a string (?).
Yes. You can do that like so:
my $handler = new IO::Scalar \$string;
See perldoc IO::Scalar
On new enough Perls, you can do the same thing with open:
open($handler, '<', \$string) or die $!;
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Wed, 11 Apr 2007 20:15:51 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: How to interchange a handle and a scalar?
Message-Id: <m2bqhumoqw.fsf@local.wv-www.com>
Bryan <bcc@nospam.net> writes:
> I am using a perl package (Data::Table) that has a function called
> fromTSV and takes a name or a handler to a TSV file.
>
> But I am generating a TSV file in memory from an XML/XSLT transform.
> I want to pop this into the Data::Table stuff, but would prefer not to
> dump it to disk and then read it back in.
With Perl 5.8.0 and newer, you can open a file handle to a scalar.
#!/usr/bin/perl
use warnings;
use strict;
require 5.8.0;
my $text = <<EOF;
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam
nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat
volutpat.
EOF
open my $handle, '<', \$text
or die "Could not open \$text: $!";
while (<$handle>) {
print;
}
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Wed, 11 Apr 2007 13:16:21 -0700
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: My script to download YouTube videos (critique wanted)
Message-Id: <ibSdnV_Xi_aP34DbnZ2dnUVZ_oytnZ2d@giganews.com>
Ignoramus13850 wrote:
(snipped childish trolling)
> I think that good programmers would not make their programs a mess by
> not using safe "my" declarations, for the sake of making a 37 second
> program into a 35 second program.
Your displayed test reports 38 seconds and 35 seconds. You
are practicing deceit. Other words, you are lying to readers.
Lying to readers is a very common behavior in this group,
especially by those thought to be "gods" of Perl.
Additionally, I did not write programmers should not make use
of my declarations. I wrote programmers should use correct
syntax for declaration of variables. Again, you are lying
to readers much in keeping with long habit of regulars here.
If you are a technician employed by Amazon, employed by Google,
employed by Microsoft, employed by any of tens of thousands of
similar companies, your displayed thinking would most likely
result in termination of your employment; a three second delay
difference for a program used millions of times per day, is
good cause to fire you.
I am curious. How does a "my" declaration render a script "safe"?
You and the other "troll gods" of this group are arguing, paraphrased,
"Use of incorrect syntax is ok."
I am, of course, highly skeptical.
Purl Gurl
------------------------------
Date: Wed, 11 Apr 2007 13:32:57 -0700
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: My script to download YouTube videos (critique wanted)
Message-Id: <MPednbA7gpBq2IDbnZ2dnUVZ_ternZ2d@giganews.com>
David Filmer wrote:
> Purl Gurl wrote:
(snipped childish trolling)
> One of the consequences of following good any programming practice is
> usually a tiny performance penalty.
Use of incorrect syntax is not a good programming practice.
You are lying to readers.
Purl Gurl
------------------------------
Date: Wed, 11 Apr 2007 23:57:08 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: My script to download YouTube videos (critique wanted)
Message-Id: <gcmq139i01c4r98c5r9mgqi9rv6l942cfb@4ax.com>
On Wed, 11 Apr 2007 13:14:09 -0500, Ignoramus13850
<ignoramus13850@NOSPAM.13850.invalid> wrote:
>On Wed, 11 Apr 2007 10:31:52 -0700, Purl Gurl <purlgurl@purlgurl.net> wrote:
[snip]
>Well, that "my" declaration makes things slower, is new to me and
>surprises me. However, I will take your word at face value.
Haha! You've just met moronzilla!!
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Wed, 11 Apr 2007 23:59:43 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: My script to download YouTube videos (critique wanted)
Message-Id: <uemq13h3fhfc7trvu1gi43ofov77r53si9@4ax.com>
On 11 Apr 2007 15:00:31 -0400, Charlton Wilbur
<cwilbur@chromatico.net> wrote:
>You might not want to do that without a bit of consideration. A quick
>look at Purl Gurl's posting history on Google Groups should indicate
>the sort of esteem that she is held in here, and how much validity her
>advice usually has. When she's right, it's usually by accident.
But "she" could easily win any competition in which any modern enough
and sane programming practice is forbidden a priori. Speaking of that
subset of Perl fit for morons, "she" certainly has inarguable skills,
hasn't "she"?
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 12 Apr 2007 00:02:43 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: My script to download YouTube videos (critique wanted)
Message-Id: <9lmq13dsv368hhvq4m4b8928ek4dtk7ttu@4ax.com>
On Wed, 11 Apr 2007 14:28:49 -0500, Ignoramus13850
<ignoramus13850@NOSPAM.13850.invalid> wrote:
>I wrote a test script to test Purl Gurl's assertion.
I wouldn't do it. No way. YMMV...
>The results are:
>
>### ::~/tmp/perl==>./my.pl
>### My took 38 seconds.
>### Global took 35 seconds.
How did you test? On the program you posted before?!? If so, then, are
you aware that it makes requests through the internet? How do you
expect that to be reliable?
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Wed, 11 Apr 2007 19:00:01 -0500
From: Ignoramus13850 <ignoramus13850@NOSPAM.13850.invalid>
Subject: Re: My script to download YouTube videos (critique wanted)
Message-Id: <95OdnQxEqOkc64DbnZ2dnUVZ_vbinZ2d@giganews.com>
On Thu, 12 Apr 2007 00:02:43 +0200, Michele Dondi <bik.mido@tiscalinet.it> wrote:
> On Wed, 11 Apr 2007 14:28:49 -0500, Ignoramus13850
><ignoramus13850@NOSPAM.13850.invalid> wrote:
>
>>I wrote a test script to test Purl Gurl's assertion.
>
> I wouldn't do it. No way. YMMV...
>
>>The results are:
>>
>>### ::~/tmp/perl==>./my.pl
>>### My took 38 seconds.
>>### Global took 35 seconds.
>
> How did you test? On the program you posted before?!? If so, then, are
> you aware that it makes requests through the internet? How do you
> expect that to be reliable?
The test script that I timed, above, had nothing to do with the
original youtube script.
i
------------------------------
Date: Wed, 11 Apr 2007 20:27:04 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: My script to download YouTube videos (critique wanted)
Message-Id: <slrnf1r2n8.jg7.tadmc@tadmc30.august.net>
Ignoramus13850 <ignoramus13850@NOSPAM.13850.invalid> wrote:
> On Wed, 11 Apr 2007 17:09:41 GMT, John W. Krahn <someone@example.com> wrote:
>> Ignoramus13850 wrote:
>>> Plz critique...
>>>
>>
>> Test your program with warnings enabled and then repost when you have fixed
>> the problems that it warns you about.
>>
>
> Good idea
And it was a good idea when enabling warnings was suggested
to you a year ago...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 11 Apr 2007 20:56:38 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: My script to download YouTube videos (critique wanted)
Message-Id: <slrnf1r4em.jg7.tadmc@tadmc30.august.net>
Ignoramus13850 <ignoramus13850@NOSPAM.13850.invalid> wrote:
> for( my $i = 0; $i < 4; $i++ ) {
foreach my $i ( 0 .. 3 ) {
> return undef;
return; # your code will do the "wrong thing" in list context
> $title = "$1";
$title = $1;
perldoc -q vars
What’s wrong with always quoting "$vars"?
> $title =~ s/(\/|\\| |\+|\`|\'|\;|\!|\(|\)|\-)/_/g;
No point in capturing if you are not going to use the captured value.
Most of those backslashes are not needed.
A character class eliminates the vertical bar noise.
With alternate delimiters you don't need to backslash the slash either.
$title =~ s#[/\\ +`';!()-]#_#g;
But a year ago I pointed out that a regex was not the right tool
for the job, and it isn't the right tool for this job either:
$title =~ tr#/\\ +`';!()-#_#;
> $title =~ s/_+/_/g;
$title =~ tr/_/_/s;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 12 Apr 2007 00:09:11 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Script to know who clicked a link?
Message-Id: <8vmq13hjqc8tjlobddkbhbkn8cjvgj4ain@4ax.com>
On 11 Apr 2007 12:35:36 -0700, usenet@DavidFilmer.com wrote:
>Lemme see if I can drag a bit of clarity out of this question.
>
>So you send them a link like this:
>
> http://www.example.com/cgi-bin/stuff.cgi?name=DavidFilmer
>
>Is that right?
No, I think that he wants the to be reported the username of the
person who clicks on "his" link when the latter is logged in a site
which has such a login procedure. 'Nuff said...
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 12 Apr 2007 00:13:36 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Script to know who clicked a link?
Message-Id: <b6nq135rak7e9vqc4nd55dfj5vvr905a6c@4ax.com>
On 11 Apr 2007 12:44:51 -0700, "PGPS" <premgrps@gmail.com> wrote:
>Assume that I know how to extract this name from the page.
>
>When he clicks on this link (javascript probably), it appends his name
>to the link and sends a query like what you stated in your message
>http://www.example.com/cgi-bin/stuff.cgi?name=DavidFilmer
>
>
>Any ideas?
Yes: it depends on the actual forum. And yes: you probably want to do
this in JS if the site permits that - it's obvious that this must be
done on the client of the person who clicks the link! I have no idea
why you think that this may have even remotely to do with Perl.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 11 Apr 2007 13:29:06 -0700
From: usenet@DavidFilmer.com
Subject: Re: Toggle between hot filehandles question
Message-Id: <1176323346.647497.157990@l77g2000hsb.googlegroups.com>
On Apr 11, 1:06 pm, "Jorge" <awks...@yahoo.com> wrote:
> Because this will be (someday:)) a production script, I need to keep a
> solid record of all the warnings, errors and such in a log as well as
> splash that same information to the terminal for the user.
>
> Therefore, I have 2 filehandles that I want to toggle between hot and
> cold -- STDOUT and LOG ($fh in subroutine).
You can use IO::Tee to multiplex the output to a file as well as the
terminal.
However, you may wish to consider a full-blown logging module. I like
Log::Dispatch. You do a lot of work at the beginning of your program
(but I use mostly boilerplate code) to set up the various logging
methods (screen, file, database, e-mail, etc) but then it's really
easy to invoke one or more of those methods at any time (depending on
the severity level of the event).
Consider this boilerplate which sets up three log methods (screen,
file, and e-mail):
######################################################################
use Log::Dispatch; ##
use Log::Dispatch::Screen; ##
use Log::Dispatch::File; ##
use Log::Dispatch::Email::MailSendmail; ##
##
my $log; ##
##
my $logdir = "/var/tmp"; ##
my @admin_email = ('usenet@davidfilmer.com') ##
##
my $add_lf = sub { my %p = @_; "$p{'message'}\n"}; ##
my $add_indent = sub {my %p = @_; " $p{'message'}"}; #for Outlook ##
my $add_timestamp = sub { my %p = @_; ##
sprintf "%s - %s", scalar(localtime), ##
$p{'message'}; }; ##
my $add_level = sub { my %p = @_; ##
sprintf "%-10s %s", ($p{'level'} =~ /debug/i) ##
? lc $p{'level'} ##
: uc $p{'level'},##
$p{'message'} }; ##
##
$log = Log::Dispatch->new ( callbacks => [$add_level, $add_lf] ); ##
##
$log ->add( Log::Dispatch::Screen ->new( ##
name => 'screen', ##
min_level => 'debug', ##
stderr => 0, ) ##
); ##
$log ->add( Log::Dispatch::File ->new( ##
name => 'file', ##
min_level => 'info', ##
filename => sprintf ( "%s/%s.log", ##
$logdir, ##
$FindBin::Script ), ##
mode => 'append', ##
callbacks => $add_timestamp, ##
)); ##
$log ->add( Log::Dispatch::Email::MailSendmail ->new( ##
name => 'email', ##
min_level => 'error', ##
to => \@admin_email, ##
subject => "ERROR in $PROGRAM_NAME", ##
callbacks => $add_indent, ##
from => sprintf ("SERVER<%s\@%s>", ##
(hostname =~ /^([^\.]*)/)[0], ##
'do-not-reply.com' ) , ##
smtp => $cfg{'email'}{'smtp'} || 'localhost', ##
)); ##
######################################################################
Now all you need to do is log an event at an appropriate error level,
such as:
$log->debug("Opening $file"); #screen only
$log->info("Added user $user") #screen + logfile
$log->error("I just jumped the shark!"); #and also sends email
You can create a method to log to a database as well, and you can use
a file logging variant that automatically rotates logfiles if you
like. I use callbacks to add newlines, and I use a callback to
timestamp log file entries.
You could set up multiple file logging methods which fire at different
severity levels, so you could keep a debug-level logfile (which you
would probably rotate more frequently) and a historical main-event
logfile (which you would rotate infrequently or never).
--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)
------------------------------
Date: 11 Apr 2007 13:44:58 -0700
From: "Jorge" <awkster@yahoo.com>
Subject: Re: Toggle between hot filehandles question
Message-Id: <1176324298.419629.199770@l77g2000hsb.googlegroups.com>
On Apr 11, 1:29 pm, use...@DavidFilmer.com wrote:
> On Apr 11, 1:06 pm, "Jorge" <awks...@yahoo.com> wrote:
>
> > Because this will be (someday:)) a production script, I need to keep a
> > solid record of all the warnings, errors and such in a log as well as
> > splash that same information to the terminal for the user.
>
> > Therefore, I have 2 filehandles that I want to toggle between hot and
> > cold -- STDOUT and LOG ($fh in subroutine).
>
> You can use IO::Tee to multiplex the output to a file as well as the
> terminal.
>
> However, you may wish to consider a full-blown logging module. I like
> Log::Dispatch. You do a lot of work at the beginning of your program
> (but I use mostly boilerplate code) to set up the various logging
> methods (screen, file, database, e-mail, etc) but then it's really
> easy to invoke one or more of those methods at any time (depending on
> the severity level of the event).
>
> Consider this boilerplate which sets up three log methods (screen,
> file, and e-mail):
>
> ######################################################################
> use Log::Dispatch; ##
> use Log::Dispatch::Screen; ##
> use Log::Dispatch::File; ##
> use Log::Dispatch::Email::MailSendmail; ##
> ##
> my $log; ##
> ##
> my $logdir = "/var/tmp"; ##
> my @admin_email = ('use...@davidfilmer.com') ##
> ##
> my $add_lf = sub { my %p = @_; "$p{'message'}\n"}; ##
> my $add_indent = sub {my %p = @_; " $p{'message'}"}; #for Outlook ##
> my $add_timestamp = sub { my %p = @_; ##
> sprintf "%s - %s", scalar(localtime), ##
> $p{'message'}; }; ##
> my $add_level = sub { my %p = @_; ##
> sprintf "%-10s %s", ($p{'level'} =~ /debug/i) ##
> ? lc $p{'level'} ##
> : uc $p{'level'},##
> $p{'message'} }; ##
> ##
> $log = Log::Dispatch->new ( callbacks => [$add_level, $add_lf] ); ##
> ##
> $log ->add( Log::Dispatch::Screen ->new( ##
> name => 'screen', ##
> min_level => 'debug', ##
> stderr => 0, ) ##
> ); ##
> $log ->add( Log::Dispatch::File ->new( ##
> name => 'file', ##
> min_level => 'info', ##
> filename => sprintf ( "%s/%s.log", ##
> $logdir, ##
> $FindBin::Script ), ##
> mode => 'append', ##
> callbacks => $add_timestamp, ##
> )); ##
> $log ->add( Log::Dispatch::Email::MailSendmail ->new( ##
> name => 'email', ##
> min_level => 'error', ##
> to => \@admin_email, ##
> subject => "ERROR in $PROGRAM_NAME", ##
> callbacks => $add_indent, ##
> from => sprintf ("SERVER<%s\@%s>", ##
> (hostname =~ /^([^\.]*)/)[0], ##
> 'do-not-reply.com' ) , ##
> smtp => $cfg{'email'}{'smtp'} || 'localhost', ##
> )); ##
> ######################################################################
>
> Now all you need to do is log an event at an appropriate error level,
> such as:
>
> $log->debug("Opening $file"); #screen only
> $log->info("Added user $user") #screen + logfile
> $log->error("I just jumped the shark!"); #and also sends email
>
> You can create a method to log to a database as well, and you can use
> a file logging variant that automatically rotates logfiles if you
> like. I use callbacks to add newlines, and I use a callback to
> timestamp log file entries.
>
> You could set up multiple file logging methods which fire at different
> severity levels, so you could keep a debug-level logfile (which you
> would probably rotate more frequently) and a historical main-event
> logfile (which you would rotate infrequently or never).
>
> --
> The best way to get a good answer is to ask a good question.
> David Filmer (http://DavidFilmer.com)
David
Thank you very much for the response. This looks like precisely what I
need. Not only is it nearly immediately functional but it appears I
can build on it as the needs arise.
Thanks again
Jorge
------------------------------
Date: Wed, 11 Apr 2007 23:49:02 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Toggle between hot filehandles question
Message-Id: <evjsd8.184.1@news.isolution.nl>
usenet@DavidFilmer.com schreef:
> Jorge:
>> Because this will be (someday:)) a production script, I need to keep
>> a solid record of all the warnings, errors and such in a log as well
>> as splash that same information to the terminal for the user.
>>
>> Therefore, I have 2 filehandles that I want to toggle between hot and
>> cold -- STDOUT and LOG ($fh in subroutine).
>
> You can use IO::Tee to multiplex the output to a file as well as the
> terminal.
>
> However, you may wish to consider a full-blown logging module. I like
> Log::Dispatch.
See also Log::Log4perl
http://search.cpan.org/search?query=log4perl
and certainly page 4 of
http://www.perl.com/pub/a/2002/09/11/log4perl.html
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Thu, 12 Apr 2007 00:18:39 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Toggle between hot filehandles question
Message-Id: <mfnq139h1hsokoej3utpk810s0ngc4ish5@4ax.com>
On 11 Apr 2007 13:06:34 -0700, "Jorge" <awkster@yahoo.com> wrote:
>Because this will be (someday:)) a production script, I need to keep a
>solid record of all the warnings, errors and such in a log as well as
>splash that same information to the terminal for the user.
>
>Therefore, I have 2 filehandles that I want to toggle between hot and
>cold -- STDOUT and LOG ($fh in subroutine).
Isn't it that you want IO::Multiplex?
>A snippet (very pruned down) is below to show how I am doing the
>toggling. As already said, it is working but I can't believe it's the
>correct way -- it's downright ugly.
Your code is still too long for me to really want to read it, but
looking at it from far enough seems to reveal many portions of similar
constructs, which loudly scream for *factorization*. (If they're
really there. Or else you have my apologies.)
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
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 325
**************************************