[25562] in Perl-Users-Digest
Perl-Users Digest, Issue: 7806 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 21 14:06:00 2005
Date: Mon, 21 Feb 2005 11:05:19 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 21 Feb 2005 Volume: 10 Number: 7806
Today's topics:
Re: Any Perl Modules to gzip and gunzip <constantin.wiemer@infineon.com>
Re: Any Perl Modules to gzip and gunzip ioneabu@yahoo.com
Correct way to inherit from 3rd party class <jonny@windmillwalton.demon.co.uk>
Re: Correct way to inherit from 3rd party class <phaylon@dunkelheit.at>
Re: Correct way to inherit from 3rd party class <jonny@windmillwalton.demon.co.uk>
Re: Correct way to inherit from 3rd party class <phaylon@dunkelheit.at>
Re: cubic root subroutine <sbryce@scottbryce.com>
Re: Form manipulation through mechcanize (perl) <glex_nospam@qwest.invalid>
Re: How to test for existance ? <nobull@mail.com>
Intercepting data flow between 2 apps <hackeras@gmail.com>
Re: Intercepting data flow between 2 apps <1usa@llenroc.ude.invalid>
Re: ithreads + signals on modern Unices brianr@liffe.com
Re: Mason hosting support? <glex_nospam@qwest.invalid>
Re: Mason hosting support? <postmaster@castleamber.com>
Re: Newbie Perl programming help (RSS & IRC) <cmw@tulpje.co.uk>
Re: Newbie Perl programming help (RSS & IRC) <cmw@tulpje.co.uk>
Re: Parameters in command line <joericochuyt@msn.com>
Re: Parameters in command line <nobull@mail.com>
Re: Parameters in command line <postmaster@castleamber.com>
Re: Parameters in command line <phaylon@dunkelheit.at>
test clearguy02@yahoo.com
Re: test <phaylon@dunkelheit.at>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 21 Feb 2005 12:48:30 +0100
From: Constantin Wiemer <constantin.wiemer@infineon.com>
Subject: Re: Any Perl Modules to gzip and gunzip
Message-Id: <cvchqe$43$1@athen03.muc.infineon.com>
arun wrote:
> Hi ,
> Is there any perl modules to compress and uncompress files, folders.
>
> Thanks
> With Regards
> Arun
>
You could use the PerlIO::gzip module which gives you the advantage that
it can handle compressed files transparently, i. e. if the file is
compressed it decompresses it, otherwise it just reads it.
Regards,
Constantin Wiemer
------------------------------
Date: 21 Feb 2005 09:04:48 -0800
From: ioneabu@yahoo.com
Subject: Re: Any Perl Modules to gzip and gunzip
Message-Id: <1109005488.240875.261390@l41g2000cwc.googlegroups.com>
Constantin Wiemer wrote:
> arun wrote:
> > Hi ,
> > Is there any perl modules to compress and uncompress files,
folders.
> >
> > Thanks
> > With Regards
> > Arun
> >
Whatever you use for compression, if you send a compressed file via
FTP, don't forget to switch to binary mode first, or you will get a
corrupt file at the other end. Also test your archive before deleting
the original. I know it seems off topic, but I went searching around
for other methods of compression for this reason when it was really a
simple FTP mistake.
All this was learned from the gzip home page, a great source of
information.
wana
------------------------------
Date: 21 Feb 2005 09:05:47 -0800
From: "jonnytheclown" <jonny@windmillwalton.demon.co.uk>
Subject: Correct way to inherit from 3rd party class
Message-Id: <1109005546.992322.165860@o13g2000cwo.googlegroups.com>
What is the correct (recommended) way to inherit from an arbitrary
class when I know nothing about its internals (and don't want to know)
but need to hold additional instance variables. The next question is
how should I implement a class that allows other programmers to inherit
from it and hold their own instance variables.
------------------------------
Date: Mon, 21 Feb 2005 18:24:54 +0100
From: phaylon <phaylon@dunkelheit.at>
Subject: Re: Correct way to inherit from 3rd party class
Message-Id: <pan.2005.02.21.17.24.53.435964@dunkelheit.at>
jonnytheclown wrote:
> What is the correct (recommended) way
My Answer: Your favorite one.
> to inherit from an arbitrary class when I know nothing about its
> internals (and don't want to know)
Well, this wipes the private interfaces from the list, so you can only
take use of the public ones. By the way: In Perl it's a package.
> but need to hold additional instance variables.
Additional instance-vars for *your* or *that* module? For yours it should
be easy.
> The next question is how should I implement a class that allows other
> programmers to inherit from it and hold their own instance variables.
In general? With good interface design.
You could tell a bit more of what you're trying to do. For general it
won't be to bad to google for "wrapper pattern".
hth,phay
--
http://www.dunkelheit.at/
The first rule of project mayhem is: you do not ask questions.
-- Fight Club
------------------------------
Date: 21 Feb 2005 10:14:07 -0800
From: "jonnytheclown" <jonny@windmillwalton.demon.co.uk>
Subject: Re: Correct way to inherit from 3rd party class
Message-Id: <1109009647.111266.124970@z14g2000cwz.googlegroups.com>
phaylon wrote:
> jonnytheclown wrote:
>
> > What is the correct (recommended) way
>
> My Answer: Your favorite one.
>
> > to inherit from an arbitrary class when I know nothing about its
> > internals (and don't want to know)
>
> Well, this wipes the private interfaces from the list, so you can
only
> take use of the public ones. By the way: In Perl it's a package.
Programming Perl 3rd Ed. P310. "A class is simply a package". I like
the word 'class', its more OO.
>
> > but need to hold additional instance variables.
>
> Additional instance-vars for *your* or *that* module? For yours it
should
> be easy.
Obviously *my*. I no nothing about *that* internally. I don't even
know what the implementation variable is (e.g. hash, array, scalar).
So, how's it easy?
>
> > The next question is how should I implement a class that allows
other
> > programmers to inherit from it and hold their own instance
variables.
>
> In general? With good interface design.
>
> You could tell a bit more of what you're trying to do. For general it
> won't be to bad to google for "wrapper pattern".
>
I'm not trying to do anything - yet. It's an academic question.
> hth,phay
>
> --
> http://www.dunkelheit.at/
>
> The first rule of project mayhem is: you do not ask questions.
> -- Fight Club
------------------------------
Date: Mon, 21 Feb 2005 19:19:17 +0100
From: phaylon <phaylon@dunkelheit.at>
Subject: Re: Correct way to inherit from 3rd party class
Message-Id: <pan.2005.02.21.18.19.16.450881@dunkelheit.at>
jonnytheclown wrote:
>> > What is the correct (recommended) way
>>
>> My Answer: Your favorite one.
Please quote only parts you are replying to.
>> Well, this wipes the private interfaces from the list, so you can
>> only take use of the public ones. By the way: In Perl it's a package.
>
> Programming Perl 3rd Ed. P310. "A class is simply a package". I like the
> word 'class', its more OO.
As you like, but I prefer 'package', because of the differences.
> Obviously *my*. I no nothing about *that* internally. I don't even know
> what the implementation variable is (e.g. hash, array, scalar). So, how's
> it easy?
You could design a module that acts as wrapper.
>> You could tell a bit more of what you're trying to do. For general it
>> won't be to bad to google for "wrapper pattern".
>>
> I'm not trying to do anything - yet. It's an academic question.
Well the academic answer I think would be: Perl has no *one* way, never.
--
http://www.dunkelheit.at/
sapere aude.
------------------------------
Date: Mon, 21 Feb 2005 10:05:41 -0700
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: cubic root subroutine
Message-Id: <UcydneCEcpZ7iYffRVn-ug@comcast.com>
Arndt Jonasson wrote:
> You may want to handle the sign separately, since letting $foo be
> negative results in NaN ("Not a number"), at least here, on
> Solaris 2.8 x86.
Same on Win32.
> Also, it may be worth making sure that the cube of an integer always
> comes back as an integer, and not with a little rounding-error,
I assume you mean that the cube root of a cube comes back an integer.
That doesn't appear to be a problem on my machine.
use strict;
use warnings;
# Demonstrate that this works for numbers that are cubes,
# including negative cubes, without rounding error.
for my $number (-20 .. 20) {
my $x = $number ** 3;
my $resp = cubicroot($x);
print "3 root of $x = $resp\n";
}
sub cubicroot {
my $x = shift;
if ($x < 0) {
return - abs($x) ** (1/3);
}
else {
return $x ** (1/3);
}
}
There are actually 3 cube roots of any number, but finding the other two
is a more complex problem.
------------------------------
Date: Mon, 21 Feb 2005 12:54:30 -0600
From: "J. Gleixner" <glex_nospam@qwest.invalid>
Subject: Re: Form manipulation through mechcanize (perl)
Message-Id: <G7qSd.410$0X4.2002@news.uswest.net>
Antwerp wrote:
> Hi,
>
> I'm trying to create a script that automatically logs in to a website, and
> then parses the index (which is unavailable without first logging on). I'm
> having difficulties, but I'm not exactly sure where they might lie.
>
> I know I need to enable cookies to login, and I believe I have done so. I
> also recognize that I need to find and submit the appropriate form data - I
> *think* am doing this correctly too. However, once I submit the form data, I am
> unable to print, load, or view the "secure" page. I would appreciate any help;
>
> -------
>
> my $mech = WWW::Mechanize->new( autocheck => 1 );
> $mech->agent_alias( 'Windows IE 6' );
> $mech->cookie_jar(HTTP::Cookies->new
> (
> file => "cookies.txt",
> autosave => 1,
> ) );
> $mech->get( $url ); #Getting the desired page
> print $mech->content(); #Printing the content of the page
> $mech->field( $login_field_name, $usna ); #this should be setting the login
> field values
> $mech->field( $password_field_name, $pawo ); #this should be setting the
> password field values
>
> $mech->submit(); #this should submit the form, causing
> #a redirect to the proper index for logged in users
>
> print $mech->content(); #Question:
> #Shouldn't this show the new content of the page -
> #that is, the member index? Why does it not do so?
Without knowing your values of $url, $login_field_name, and
$password_field_name, and what your final print displays, who knows.
The code looks accurate. Is anything written to cookies.txt? If there
is more than one form on the page, then you may want to look at the
submit_form() method.
------------------------------
Date: Mon, 21 Feb 2005 13:56:26 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: How to test for existance ?
Message-Id: <cvcp07$rad$1@sun3.bham.ac.uk>
no spam wrote:
> Here's a small script to show what I am trying to do:
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> #!/usr/bin/perl -w
>
> sub print_yep
> {
> print "yep...\n";
> }
>
>
> $function1 = "print_yep";
> $function2 = "rubbish";
>
> $vector->{ACTION1} = \&$function1;
> $vector->{ACTION2} = \&$function2;
>
> print "something's fishy !\n" if (! exists $vector->{ACTION2});
>
> $vector->{ACTION1}();
> $vector->{ACTION2}();
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> How can I test if a function exist or not ?
OK first thing you are checking for existance in the wrong way.
exists($vector->{ACTION2}) reports if the hash element exists.
exists(&{$vector->{ACTION2}}) reports if the function referenced by the
hash element exists.
Unfortunately this only works for symbolic references because as Sinan
mentioned the act of creating a hard reference is autovivificational.
You should be able to get around this is you use defined() (which gives
slightly different information[1]) but you can't. The reason for this
is a truely fascinating bug in Perl that I described in my Usenet Gems
talk YAPC::Europe::2004. (Slides are available on
http://birmingham.pm.org/ ).
[1] exists() is true but defined() false for functions for which there
is a forward declaration but no definition yet. This may often apply to
functions that are autoloaded.
------------------------------
Date: Mon, 21 Feb 2005 16:06:48 +0000 (UTC)
From: Richard Anderson <hackeras@gmail.com>
Subject: Intercepting data flow between 2 apps
Message-Id: <Xns9604B883A12FBhackerasgmailcom@194.177.210.210>
Subject: Re: Making an app return false information [was: feeding false
anapp]
From: Richard Anderson <hackeras@gmail.com>
Newsgroups: alt.hacker
Jona Joachim <jaj13@web.de> wrote in news:42166b9f$1@news.vo.lu:
>| You mean that his chess server has necceserilly have a hostname except
>| the standard ip address ?
> Nope, that's the problem. If he doesn't I think you can't use the
> "hosts"-file method
Well i checkes it out. It does not have a hostname, neither it gives you
the opportunity to change to which ip address tou ish to connect. He
programmed it in a way that an esoteric mechanism knows exaclty his
servers ip address to connect to. :|
That makes things even more difficult to overcome, but even more
challengable too!
>| All data flow passes through the firewall before travels to the
internet
>| and then the chess server, so in this way why cant we use the personal
>| firewall to capture all the traveling data before allow them to fly
over
>| the internet?
> Because the firewall is not meant to be used for this job and that's
> the reason why no such feature is included.
There must be some way though. Because the firewall is an intermediate
between apps and net all data flow pass through it and many times
especially Firewalls with Statefull Packet Inspection can check
incoming/outcoming data flow to mark it as dangerous if it matches
againast its trojan/worm/vulnerabality database against the firewalls
database for possible data flow danger. This feature is extremely
helpfull if a windows service that listens for communication in some port
is vulnerable, and not SP1 or SP2 installed by the user side, so the only
way the user is to be safe is by having a firewall thet blocks those in
danger services (if the user knows them of course) or even better have
the SPI personal firewall block it for him.
I gave this example to state that if the firewall can do such a thing
then of course can manage the bypassing data flow for an outgoing
connection!
Do you also agree with me?
But if yes then how we can take advanatge of that ?!?
**************************************************
The above was o thread i had in alt.hacker
My question is can a firewall intercept tha data flow between 2
applications, one running on localhost and one in an inetserver, so then
we can have the on a firewall log file and finally have the chance to
alter them?
Thank you!
------------------------------
Date: 21 Feb 2005 17:56:04 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Intercepting data flow between 2 apps
Message-Id: <Xns96048393D441Fasu1cornelledu@132.236.56.8>
Richard Anderson <hackeras@gmail.com> wrote in
news:Xns9604B883A12FBhackerasgmailcom@194.177.210.210:
> My question is can a firewall intercept tha data flow between 2
> applications, one running on localhost and one in an inetserver, so
> then we can have the on a firewall log file and finally have the
> chance to alter them?
*PLONK*
Sinan
------------------------------
Date: Mon, 21 Feb 2005 14:25:25 +0000
From: brianr@liffe.com
Subject: Re: ithreads + signals on modern Unices
Message-Id: <vtpsyu7zxm.fsf@ssdevws28.admin.liffe.com>
Thomas Jahns <Thomas.Jahns@epost.de> writes:
> brianr@liffe.com writes:
>> I would recommend finding a different way of doing what you want.
>
> As it seems, I don't have any easy way to do this. One of the threads is
> blocked in a recv (which AFAIK is actually libc's recvfrom) and on
> certain conditions I need to wake it, immediately.
How about blocking on select rather than recv. Your file descriptor
set would include a pipe (for example) that you could use to unblock
the thread in the event of "certain conditions".
HTH
--
Brian Raven
You tell it that it's indicative by appending $!. That's why we made $!
such a short variable name, after all. :-)
-- Larry Wall in <199709081801.LAA20629@wall.org>
------------------------------
Date: Mon, 21 Feb 2005 12:22:45 -0600
From: "J. Gleixner" <glex_nospam@qwest.invalid>
Subject: Re: Mason hosting support?
Message-Id: <VFpSd.408$0X4.1588@news.uswest.net>
briansmccabe@gmail.com wrote:
> Thanks very much. I will investigate this option.
Also check the appropriate Mason Web site:
http://www.masonhq.com/
------------------------------
Date: 21 Feb 2005 18:29:24 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Mason hosting support?
Message-Id: <Xns96047F0DD5BA7castleamber@130.133.1.4>
wrote:
> I apologize if this post is in the wrong area. It was about the most
> relevant (or somewhat relevant) NG I could find.
>
> I am wondering if anyone can make a recommendation for a reputable,
> stable hosting provider that can host a site written in Mason. My
> current provider charges me only 5 dollars a month, but I anticipate
> having to shell out a bit more than that.
hostingforabuck.com has offered me a Mason option (I need it in the
future). Don't know if they charge more. Ask for Mike, and mention my name,
it might ring a bell, and do some magic :-D
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: 21 Feb 2005 08:58:51 -0800
From: "Chris" <cmw@tulpje.co.uk>
Subject: Re: Newbie Perl programming help (RSS & IRC)
Message-Id: <1109005131.407598.249510@z14g2000cwz.googlegroups.com>
Thanks for your help. I have now progressed more. However I have hit
another problem. I have worked out where I need to define the $rss and
$enable variables and that in each sub() that I need to do something
like a my ($rss, $enable) = @_; to allow the sub() access to the
variables. The problem that I think I have now is that it seems that
the data that is in $rss & $enable is not passed back out of the
sub's() when the sub() ends. So when the program comes to want to save
the data, it can't because the variable's are blank.
Do you understand what I mean?
The error that I get when the rss saves is
Can't call method "save" on an undefined value at ./sharetvrss.pl line
171, <CFGFILE> line 36.
Below is the latest version of the program.
I think that by the time I get this program fixed, I will definatly
understand how variables are passed around.
thanks
chris
#!/usr/bin/perl
use strict;
use Net::IRC;
use XML::RSS;
sub GetSetting
{
my ($setting,$config_file)=@_;
open(CFGFILE,"<$config_file")
or die "Can't open configuration file ($config_file)";
my @slist=<CFGFILE>;
foreach my $selem (@slist)
{
if (index($selem,"#")==0) { next; }
my @ln=split("=",$selem);
if ($ln[0] =~ /$setting/i)
{
chomp $ln[1];
return $ln[1];
}
}
close CFGFILE;
}
# =============
# MAIN BOT CODE
# =============
# Set our configuration file
my $configuration_file = "sharetvrss.cfg";
# You can start the bot with a config file as a
# commandline argument. Without the argument,
# the bot loads its settings from "gir.cfg", in
# the same directory as the bot.
if($#ARGV==0) { $configuration_file=$ARGV[0]; }
# Now, we can load in our script's settings
my $cfg_nick=GetSetting("nick",$configuration_file);
my $cfg_altnick=GetSetting("altnick",$configuration_file);
my $cfg_ident=GetSetting("ident",$configuration_file);
my $cfg_port=GetSetting("port",$configuration_file);
my $cfg_server=GetSetting("server",$configuration_file);
my $cfg_channel=GetSetting("channel", $configuration_file);
my $rss = new XML::RSS(version => '0.91');
my $enable = 1;
# Just about all of the settings are "strings", except
# for the "port". Let's make sure that that setting
# is numerical, and if not, set it to the most common
# port, 6667:
if($cfg_port=~/\D/) { $cfg_port=6667; }
# Now that all of our settings are loaded in,
# let's create the IRC object
my $irc = new Net::IRC;
print "Creating connection to IRC server...";
my $conn = $irc->newconn(Server => "$cfg_server",
Port => $cfg_port,
Nick => "$cfg_nick",
Ircname => "$cfg_ident",
Username => "$cfg_ident")
or die "Can't connect to IRC server.";
print "done!\n";
$conn->{channel} = '#sonic';
# With that out of the way, let's create
# some subs for our object handlers
# What our bot will do when it finishes
# connecting to the IRC server
sub on_connect {
my $self = shift;
print "*** Connected to IRC.\n";
$conn->join("$cfg_channel");
print "*** Joined Channel: $cfg_channel.\n";
}
# This sub will print various
# incoming date while we're still
# connecting to IRC
sub on_init {
my ($self, $event) = @_;
my (@args) = ($event->args);
shift (@args);
print "*** @args\n";
}
# This sub will handle what happens when the
# bot receives public (channel) text.
sub on_public {
my ($self, $event, $rss, $enable) = @_;
my @to = $event->to;
my ($nick, $mynick) = ($event->nick, $self->nick); # Sender text,
Bot nick
my $host=$event->host; # Sender's hostname
my ($arg) = ($event->args); # The message
# Here's where we want to "parse" channel text
print "<$nick> $arg\n";
if ($nick eq "eZebra" && $arg=~/ed2k:\/\// && $enable==1)
{
#&add_ed2k();
$rss->add_item(
link => "$arg"
);
}
if ($nick eq "eZebra" && $arg=~m/--- Latest links: ---/i)
{
#&start_rss();
$enable=1;
$rss = new XML::RSS(version => '0.91');
$rss->channel(
title => 'RSS Feed',
link => 'irc://irc.efnet.net/test',
description => 'Toast'
);
}
if ($nick eq "eZebra" && $arg=~m/------/i)
{
#&end_rss();
$rss->save("/home/cmw/public_html/test/testss.rss");
$enable=0;
}
}
# This sub will handle what happens when the
# bot receives private message text
sub on_msg {
my ($self, $event) = @_;
my ($nick) = $event->nick; # Message Sender
my ($arg) = ($event->args); # Message Text
my $host=$event->host;
# Here's where we want to "parse" message text
print " - $nick - $arg\n";
}
# This sub will get triggered if our bot's nick
# is taken, setting it to our alternate nick.
sub on_nick_taken {
my ($self) = shift;
$self->nick($cfg_altnick);
}
sub on_join {
# get our connection object and the event object, which is
passed
# with this event automatically
my ($conn, $event) = @_;
# this is the nick that just joined
my $nick = $event->{nick};
# say hello to the nick in public
#$conn->privmsg($conn->{channel}, "Hello, $nick!");
if ($nick = "mynick")
{
$conn->mode('#sonic', '+o', 'mynick');
print "*** Modifying $nick Mode to: +o\n";
}
}
# Now that all of our handler subs are created,
# let's install them
print "Installing local handlers...";
$conn->add_handler('public', \&on_public);
$conn->add_handler('msg', \&on_msg);
$conn->add_handler('join', \&on_join);
print "done!\nInstalling global handlers...";
$conn->add_global_handler([ 251,252,253,254,302,255 ], \&on_init);
$conn->add_global_handler([376, 422], \&on_connect);
$conn->add_global_handler(433, \&on_nick_taken);
print "done!\n";
# Everything's installed, so there's nothing
# holding up back from starting up!
$irc->start;
------------------------------
Date: 21 Feb 2005 09:19:13 -0800
From: "Chris" <cmw@tulpje.co.uk>
Subject: Re: Newbie Perl programming help (RSS & IRC)
Message-Id: <1109006353.147798.163520@g14g2000cwa.googlegroups.com>
Thanks for your help. I have now progressed more. However I have hit
another problem. I have worked out where I need to define the $rss and
$enable variables and that in each sub() that I need to do something
like a my ($rss, $enable) = @_; to allow the sub() access to the
variables. The problem that I think I have now is that it seems that
the data that is in $rss & $enable is not passed back out of the
sub's() when the sub() ends. So when the program comes to want to save
the data to rss, it can't because it thinks the variables are empty and
therefore crashes the program with the below error.
Do you understand what I mean?
The error that I get when the rss saves is
Can't call method "save" on an undefined value at ./sharetvrss.pl line
171, <CFGFILE> line 36.
Below is the latest version of the program.
thanks
chris
#!/usr/bin/perl
use strict;
use Net::IRC;
use XML::RSS;
sub GetSetting
{
my ($setting,$config_file)=@_;
open(CFGFILE,"<$config_file")
or die "Can't open configuration file ($config_file)";
my @slist=<CFGFILE>;
foreach my $selem (@slist)
{
if (index($selem,"#")==0) { next; }
my @ln=split("=",$selem);
if ($ln[0] =~ /$setting/i)
{
chomp $ln[1];
return $ln[1];
}
}
close CFGFILE;
}
# =============
# MAIN BOT CODE
# =============
# Set our configuration file
my $configuration_file = "sharetvrss.cfg";
# You can start the bot with a config file as a
# commandline argument. Without the argument,
# the bot loads its settings from "gir.cfg", in
# the same directory as the bot.
if($#ARGV==0) { $configuration_file=$ARGV[0]; }
# Now, we can load in our script's settings
my $cfg_nick=GetSetting("nick",$configuration_file);
my $cfg_altnick=GetSetting("altnick",$configuration_file);
my $cfg_ident=GetSetting("ident",$configuration_file);
my $cfg_port=GetSetting("port",$configuration_file);
my $cfg_server=GetSetting("server",$configuration_file);
my $cfg_channel=GetSetting("channel", $configuration_file);
my $rss = new XML::RSS(version => '0.91');
my $enable = 1;
# Just about all of the settings are "strings", except
# for the "port". Let's make sure that that setting
# is numerical, and if not, set it to the most common
# port, 6667:
if($cfg_port=~/\D/) { $cfg_port=6667; }
# Now that all of our settings are loaded in,
# let's create the IRC object
my $irc = new Net::IRC;
print "Creating connection to IRC server...";
my $conn = $irc->newconn(Server => "$cfg_server",
Port => $cfg_port,
Nick => "$cfg_nick",
Ircname => "$cfg_ident",
Username => "$cfg_ident")
or die "Can't connect to IRC server.";
print "done!\n";
$conn->{channel} = '#sonic';
# With that out of the way, let's create
# some subs for our object handlers
# What our bot will do when it finishes
# connecting to the IRC server
sub on_connect {
my $self = shift;
print "*** Connected to IRC.\n";
$conn->join("$cfg_channel");
print "*** Joined Channel: $cfg_channel.\n";
}
# This sub will print various
# incoming date while we're still
# connecting to IRC
sub on_init {
my ($self, $event) = @_;
my (@args) = ($event->args);
shift (@args);
print "*** @args\n";
}
# This sub will handle what happens when the
# bot receives public (channel) text.
sub on_public {
my ($self, $event, $rss, $enable) = @_;
my @to = $event->to;
my ($nick, $mynick) = ($event->nick, $self->nick); # Sender text,
Bot nick
my $host=$event->host; # Sender's hostname
my ($arg) = ($event->args); # The message
# Here's where we want to "parse" channel text
print "<$nick> $arg\n";
if ($nick eq "eZebra" && $arg=~/ed2k:\/\// && $enable==1)
{
#&add_ed2k();
$rss->add_item(
link => "$arg"
);
}
if ($nick eq "eZebra" && $arg=~m/--- Latest links: ---/i)
{
#&start_rss();
$enable=1;
$rss = new XML::RSS(version => '0.91');
$rss->channel(
title => 'RSS Feed',
link => 'irc://irc.efnet.net/test',
description => 'Toast'
);
}
if ($nick eq "eZebra" && $arg=~m/------/i)
{
#&end_rss();
$rss->save("/home/cmw/public_html/test/testss.rss");
$enable=0;
}
}
# This sub will handle what happens when the
# bot receives private message text
sub on_msg {
my ($self, $event) = @_;
my ($nick) = $event->nick; # Message Sender
my ($arg) = ($event->args); # Message Text
my $host=$event->host;
# Here's where we want to "parse" message text
print " - $nick - $arg\n";
}
# This sub will get triggered if our bot's nick
# is taken, setting it to our alternate nick.
sub on_nick_taken {
my ($self) = shift;
$self->nick($cfg_altnick);
}
sub on_join {
# get our connection object and the event object, which is
passed
# with this event automatically
my ($conn, $event) = @_;
# this is the nick that just joined
my $nick = $event->{nick};
# say hello to the nick in public
#$conn->privmsg($conn->{channel}, "Hello, $nick!");
if ($nick = "mynick")
{
$conn->mode('#sonic', '+o', 'mynick');
print "*** Modifying $nick Mode to: +o\n";
}
}
# Now that all of our handler subs are created,
# let's install them
print "Installing local handlers...";
$conn->add_handler('public', \&on_public);
$conn->add_handler('msg', \&on_msg);
$conn->add_handler('join', \&on_join);
print "done!\nInstalling global handlers...";
$conn->add_global_handler([ 251,252,253,254,302,255 ], \&on_init);
$conn->add_global_handler([376, 422], \&on_connect);
$conn->add_global_handler(433, \&on_nick_taken);
print "done!\n";
# Everything's installed, so there's nothing
# holding up back from starting up!
$irc->start;
------------------------------
Date: Mon, 21 Feb 2005 10:07:57 -0500
From: "yusufdestina" <joericochuyt@msn.com>
Subject: Re: Parameters in command line
Message-Id: <9ea58239d596ebe9595ac3a6ec3a863b@localhost.talkaboutprogramming.com>
Ok, the problem is, the first appl. isn't a perl script, but it has to pass
arguments to the compiled perl script.
No I looked at system doc, but I can't find anything relevant here.
Maybe my question was a bit confusing,
Some time ago i found an example of executing a perl script with custom
parameters, problem is i can't find it anymore.
------------------------------
Date: Mon, 21 Feb 2005 17:38:23 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Parameters in command line
Message-Id: <cvd60c$4mn$1@sun3.bham.ac.uk>
yusufdestina wrote:
> Ok, the problem is, the first appl. isn't a perl script, but it has to pass
> arguments to the compiled perl script.
Why do you consider this to be a problem?
> No I looked at system doc, but I can't find anything relevant here.
When you say "system doc" do you mean "the doumentation of the system()
function in the programming language in which app 1 is written"? If so
that is a problem with documentation of that language and should be
addressed in a forum where that lanugage is discussed.
> Maybe my question was a bit confusing,
Yes, and it still is.
> Some time ago i found an example of executing a perl script with custom
> parameters, problem is i can't find it anymore.
To execute a perl script with paraters the syntax at the command line is:
perl script.pl param1 param2 param3
To execute a PAR compiled perl script with paraters the syntax at the
command line is:
script.exe param1 param2 param3
How you'd do this from inside another application is a question about
that application and/or the programming language in which it is written
and has nothing to do with Perl.
Did you have a question that does relate to Perl?
(Using PSI::ESP I guess it perhaps you might have a question about using
CGI.pm in debug mode).
------------------------------
Date: 21 Feb 2005 18:27:28 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Parameters in command line
Message-Id: <Xns96047EB9CFB60castleamber@130.133.1.4>
Brian McCauley wrote:
> To execute a perl script with paraters the syntax at the command line
> is:
>
> perl script.pl param1 param2 param3
hmmm... or
--foo=bar -v -t -tva
Sometimes:
program -h
program --help
or just program
might reveal how to use it.
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Mon, 21 Feb 2005 19:32:17 +0100
From: phaylon <phaylon@dunkelheit.at>
Subject: Re: Parameters in command line
Message-Id: <pan.2005.02.21.18.32.16.642300@dunkelheit.at>
John Bokma wrote:
> Brian McCauley wrote:
>
>> perl script.pl param1 param2 param3
>
> hmmm... or
>
> --foo=bar -v -t -tva
What's the difference? Except the strings themselves. You could also do a
perl script name_is_value
and split in script by /_is_/i
--
http://www.dunkelheit.at/
sapere aude.
------------------------------
Date: 21 Feb 2005 08:46:20 -0800
From: clearguy02@yahoo.com
Subject: test
Message-Id: <1109004380.084826.182830@f14g2000cwb.googlegroups.com>
test
------------------------------
Date: Mon, 21 Feb 2005 17:54:26 +0100
From: phaylon <phaylon@dunkelheit.at>
Subject: Re: test
Message-Id: <pan.2005.02.21.16.54.26.859712@dunkelheit.at>
clearguy02 wrote:
> test
print "Please use one of the test-groups" and plonk( $msg{from} );
--
http://www.dunkelheit.at/
thou shallst fear...
------------------------------
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 V10 Issue 7806
***************************************