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: [FishMonger] Script to remove features of a subscriber line.: Edit Log


Jan 8, 2009, 1:07 PM

Views: 14741
Re: [FishMonger] Script to remove features of a subscriber line.

In Reply To
The creation of the $t telnet object should include error handling just in-case it fails.

It's better to use lexical vars for the filehandles instead of the barewords

This is a minor style issue, but instead of:

if($number =~ /^6/){

I'd probably do this:

next unless $number =~ /^6\d+$/;

which has the effect of reducing the indentation by 1 level and ensures that your $number var actually holds an integer and not something like this: 63fg7.

I'd move
print "The number is:$number\n";
up a couple lines so that it's not in the middle of the telnet calls.

I'd add a few comments on exactly what the code is supposed to be doing and expected results.

I'd add a little vertical white space (i.e, blank lines) to improve readability.

I don't follow with the next unless.. you pointed out.. if you could show me here.. I'd appreciate it. Below I did the other stuff you advised on.

# This is a script that will telnet into a telcom switch,
# query a subscriber's number (sn) and check if the sn has
# data service in the account.

use strict;
use warnings;
use Net::Telnet;

my $user="user";
my $pass="pass";
my $server="host";
my $t = Net::Telnet->new($server);
$t->waitfor('/Enter User Name/');
$t->waitfor('/Enter Password/');

# Open LIST to read the subscriber numbers from list.txt.
# Open WRITE, a blank file to write in the subcriber numbers that have the data service.

open(LIST,'<', "list.txt")
or die "Can't open 'list.txt' $!";

open(WRITE,'>>', "data_numbers.txt")
or die "Can't open 'data_numbers.txt' $!";

while(my $number = <LIST>){
if($number =~ /^6|^2/){
print "The number is: $number\n";
$t->print("qhlr $number");

# Capturing the output.

my ($output) = $t->waitfor('/>/');
print "The output is: $output\n";

# Output is striped of \n and converted into a single line.

$output =~ s/\n//g;

# Checking the single line if it contains CSO: or QOPSI:.
# If match is found, then the number is written into data_numbers.txt.
# If not found, while loop prints a spacer of --- then it goes to the next number.

if($output =~ /CSO:|QOSPI:/){
print "The number has Data Service.\n";
print WRITE $number;
} else{
print "The number does NOT have Data Service.\n";

print "-------------------------------------------\n";

close LIST;
close WRITE;

# After all numbers in the loop have been queried, the session is closed.

$t->print("quit all;logout");
print "The Session has Ended!\n";

(This post was edited by cuboidgraphix on Jan 8, 2009, 1:10 PM)

Edit Log:
Post edited by cuboidgraphix (User) on Jan 8, 2009, 1:10 PM

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

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