charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Fri Apr 02, 2010 8:19 am
Perlscript help, please. |
For starters, I've never really dabbled in the art of Perl. That being said, I know of someone who makes a LOT of scripts in Perl, and occasionally he shares the information with me. Today was one such occasion. It's a simple script overall, but it's not returning expected output. I'm fairly certain I've done everything correct as far as $zvar->varname, but if someone would look over it to see if there's anything wrong that I need to change, I'd appreciate it.
Alias ctelc stores two arguments, a site and a channel, then calls the ctel alias, which is completely perl. The ctel alias tests a connection to a site to see if it passes or fails. Running it the first time, despite getting an incorrect answer, it seems to be okay. For example:
ctelc aardmud.org echo returns:
Checking site: aardmud.org
Connection to aardmud.org failed.
It should say succeeded, because I'm actually ON aardmud.org, so I know there's a connection. Now, when I do the following:
ctelc someothersite.com echo
I get instead:
Checking site: aardmud.org
Connection to aardmud.org failed.
It appears that Perl isn't updating the variable correctly, as I can visually confirm that the variables have been updated otherwise. I tested in a blank session, using $sess->EchoStr("Testing variable: " . $zvar->test . "\n",15), and it correctly updated the variable each time, so it's not a bug in that respect. Therefore, I'm hoping someone can make heads or tails out of the code below and return to me a working script. Much appreciated!
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<alias name="ctel" language="PerlScript" copy="yes">
<value><![CDATA[use Net::Telnet;
$site=$zvar->ctelsite;
$error="success";
$channel="echo";
$channel=$zvar->ctelchan;
$sess->EchoStr("Checking site: " . $site . "\n",15);
$connection=Net::Telnet->new(Timeout => 5,
Host => "$site",
Port=>80,
Errmode => sub {&error;});
sub error {
$error="failed"
}
$sess->SendStr($channel . " Connection to " . $site . " " . $error . "\n");]]></value>
</alias>
<alias name="ctelc" copy="yes">
<value>ctelsite=%1
ctelchan=%2
ctel</value>
</alias>
</cmud>
|
Charneus |
|