467,113 Members | 1,314 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,113 developers. It's quick & easy.

Need help with REGEX

Folks its been awhile (5 years) since I have done anything with Perl so I
consider myself back at newbie statis :(
#strict on

use Net::Telnet ();

$t = new Net::Telnet (Timeout =10,Prompt ='/\</' ); #

$t->open(Host ="X.X.X.X");

$t->waitfor('/ENTER USERNAME \</');
$t->print("XXXXXXX");
$t->waitfor('/ENTER PASSWORD \</');
$t->print("XXXXXXX");
$t->waitfor('/\</')
or die "No Prompt";

@out1 = $t->get;

# -------------- #
# Dump all trees #
# -------------- #

@RIR = $t->cmd(String ="ZRIR:;", Output_record_separator ="\n") or die
"EEEK";
print @RIR;

$n=0;
while ($RIR[$n]) {
if ($RIR[$n] =~ m/^TREE/){
$line = $RIR[$n];
$line =~ /\d/;
print $line . "\n";
}
$n++;
}
Now my problem is this. The Net::Telnet command fills my array with lines
like the following

TREE= 950 ATYPE=N TON=INT
DIGITS AL NBR RT CT SP NL RC DEST CHI CNT
SDEST
1 0 1011 SPR NGC 11 32 APR 335 2 N 31

ATYPE=N TON=NAT
DIGITS AL NBR RT CT SP NL RC DEST CHI CNT
SDEST
671456 0 900 SPR SC 1 32 APR 336 2 N 33

ATYPE=N TON=NAT
DIGITS AL NBR RT CT SP NL RC DEST CHI CNT
SDEST
671476 0 900 SPR SC 1 32 APR 336 2 N 33

My code if ($RIR[$n] =~ m/^TREE/) is successfully REGEX for my "TREE= 950
ATYPE=N TON=INT "

Now want I want to do is a REGEX to pull ONLY the digits out of this (950)
and assign them to s $string. Obviosly my $line =~ /\d/; isn't working
and
I am braindead on REGEX since it has been so long.

Any and all help is greatly appricited.

BR Mike

Oct 23 '08 #1
  • viewed: 1413
Share:
1 Reply
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'm sure there's a better way of doing this:

$v="TREE= 950 ATYPE=N TON=INT ";

$v=~m/(\d)(\d)(\d)/;

$s=$1 . $2 . $3;

Pedro

Michael R. McPherson Pierotti wrote:
Folks its been awhile (5 years) since I have done anything with Perl so I
consider myself back at newbie statis :(
#strict on

use Net::Telnet ();

$t = new Net::Telnet (Timeout =10,Prompt ='/\</' ); #

$t->open(Host ="X.X.X.X");

$t->waitfor('/ENTER USERNAME \</');
$t->print("XXXXXXX");
$t->waitfor('/ENTER PASSWORD \</');
$t->print("XXXXXXX");
$t->waitfor('/\</')
or die "No Prompt";

@out1 = $t->get;

# -------------- #
# Dump all trees #
# -------------- #

@RIR = $t->cmd(String ="ZRIR:;", Output_record_separator ="\n") or die
"EEEK";
print @RIR;

$n=0;
while ($RIR[$n]) {
if ($RIR[$n] =~ m/^TREE/){
$line = $RIR[$n];
$line =~ /\d/;
print $line . "\n";
}
$n++;
}
Now my problem is this. The Net::Telnet command fills my array with lines
like the following

TREE= 950 ATYPE=N TON=INT
DIGITS AL NBR RT CT SP NL RC DEST CHI CNT
SDEST
1 0 1011 SPR NGC 11 32 APR 335 2 N 31

ATYPE=N TON=NAT
DIGITS AL NBR RT CT SP NL RC DEST CHI CNT
SDEST
671456 0 900 SPR SC 1 32 APR 336 2 N 33

ATYPE=N TON=NAT
DIGITS AL NBR RT CT SP NL RC DEST CHI CNT
SDEST
671476 0 900 SPR SC 1 32 APR 336 2 N 33

My code if ($RIR[$n] =~ m/^TREE/) is successfully REGEX for my "TREE= 950
ATYPE=N TON=INT "

Now want I want to do is a REGEX to pull ONLY the digits out of this (950)
and assign them to s $string. Obviosly my $line =~ /\d/; isn't working
and
I am braindead on REGEX since it has been so long.

Any and all help is greatly appricited.

BR Mike
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkkFbLcACgkQvUI03qKHSRrbmwCeMi8HJg0gXS gDQsshLi9+uzR/
pcUAn1f0t7pWubhjjO2ALUSyJUW7xX8E
=rCw7
-----END PGP SIGNATURE-----
Oct 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Michael R. Pierotti | last post: by
1 post views Thread by hillcountry74 | last post: by
9 posts views Thread by jmchadha@gmail.com | last post: by
7 posts views Thread by Extremest | last post: by
15 posts views Thread by morleyc@gmail.com | last post: by
3 posts views Thread by =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post: by
8 posts views Thread by Alexander Vasilevsky | last post: by
4 posts views Thread by Danny Ni | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.