CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Advanced: Re: [KevinR] Help with parse words please.: Edit Log


Feb 22, 2009, 6:43 AM

Views: 12139
Re: [KevinR] Help with parse words please.

Here's my final code.

# This is a script that will telnet into the MTX and gather the BRSTAT OM(s).

# Declare 'use' statements
use DBI;
use strict;
use warnings;
use DBD::mysql;
use Net::Telnet;
use Text::ParseWords;
use POSIX qw/strftime/;

# Establish the MySQL connection
$host = 'localhost';
$database = 'db';
$usr = 'USR';
$pwd = 'PWD';

# Data Source Name
$dsn = "dbi:mysql:$database:localhost:3306";

# Perl DBI connect
$dbh = DBI->connect($dsn, $usr, $pwd);

# Establish the Telnet Connection
$t = Net::Telnet->new($server);
$t->waitfor('/Enter User Name/');
$t->waitfor('/Enter Password/');
$t->print("logutil;open act 102");

# Collecting data output
($data) = $t->waitfor('/>/');


# Stripping the data output of lines, ms and %.
$data =~ s/(\n)|(ms)|(%)//g;

# Short script to print the output in a text file for
# my($FH,$FILE);
# $FILE = "sample.txt";
# open $FH, '>', $FILE or die "Can't open '$FILE' $!";
# print $FH $data;
# close $FH;

if($data =~ /^SPEEDNET/){

# Parsing the Line
my ($TIME,$Catmp,$Lorig,$Torig,$ToAnn,$Cpocc,$Conctr,$OAvgDel,$O95,$PAvgDel,$P95,$BAvgDel,$B95,$RTrip, $Origdeny,$Inefdeny,$CPloovfl,$CPsuic,$CPtrap,$LCMdtsr,$LMdtsr) = (quotewords('[\s]+', 0, $data))[3,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47];

# Date variable
my $DATE = strftime("%Y-%m-%d", localtime(time));
# Prepare and execute query to insert into the database
$query = "INSERT INTO ACT_102 VALUES('$DATE','$TIME','$Catmp','$Lorig','$Torig','$ToAnn','$Cpocc','$Conctr','$OAvgDel','$O95','$PAvgDel', '$P95','$BAvgDel','$B95','$RTrip','$Origdeny','$Inefdeny','$CPloovfl', '$CPsuic','$CPtrap','$LCMdtsr','$LMdtsr')";
$sth = $dbh->prepare($query);


Don't know what rating my script has... but I tried to use best perl practices. :)

(This post was edited by cuboidgraphix on Feb 22, 2009, 6:46 AM)

Edit Log:
Post edited by cuboidgraphix (User) on Feb 22, 2009, 6:46 AM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives