Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple regex - finding a substring

Status
Not open for further replies.

lupidus

MIS
Jun 1, 2003
30
US
Anyone know why this regular expression search isn't working properly?

I'm using use Net::Telnet::Cisco; to populate the @output variable if that matters..

Code:
#my $success = "Success rate is 0 percent";
my $success = "Success";
@output = $session->cmd(String => join (' ', 'ping', $ip),
   		        Timeout => 20,
			 );
print @output; # ok to here..
# found the substring
if ($o =~ /$success/s) 
{
    print "ISDN connection to $ip ($desc) failed\n";
} else 
 # substtring not found
{ 
    print "ISDN connection to $ip ($desc) possibly sucessful\n";
}

Sample contents of @output variable:

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.10.10.10, timeout is 2 seconds:

.May 16 16:30:26 CDT: Se2/1:23 DDR: rotor dialout [priority]
.May 16 16:30:26 CDT: Se2/1:23 DDR: Dialing cause ip (s=10.10.10.10, d=10.10.10.10)
.May 16 16:30:26 CDT: Se2/1:23 DDR: Attempting to dial 1233454567.....
Success rate is 0 percent (0/5)
ISDN connection to 10.10.10.10 (Test Site, USA) possibly successful


As you can see , the script should definitely find the substring 'Success' in @output above, but it doesn't. I've tried to not treat the string as a single line (by removing /s ) but the problem remains. I know this is really basic but I've poured over a lot of material on this topic and no variation of whatI've read has helped.

Thanks for any help..

 
Er... where does $o get set to anything? In some other part of the script, perhaps?

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Still doesn't work. Here's the revised code:

Code:
while ( <INFILE> ) {
   # Process non-commentary lines only.
	if ( ! /^#/ ) {
      ++$i;
      chomp;
      ( $ip, $desc, $phn, $rtrname ) = split( ':' );
      print "\nProbing: $ip; Desc: $desc\n";                      
 @output = $session->cmd(String => join (' ', 'ping', $ip),
					 Timeout => 20,
			 );
 print @output; 
# found the substring
if (@output =~ /($success)/s)
{
  print "ISDN connection to $ip ($desc) failed\n";
} else
# substtring not found
{
  print "ISDN connection to $ip ($desc) possibly successful\n";
}
                              
  }
}

I do get a warning about the 'if (@output =~ /($success)/s)' line, but don't quite know what impact it may have , if any:

Applying pattern match (m//) to @array will act on scalar(@array) at u:\isdn_probe\isdnprobe_v2.pl line 112.


 
Solved my problem.. I was searching for a string in an array of strings so the following was needed:

Code:
foreach $string (@output) {
						print "checking for '$success' in: $string";
    if ($string =~ /$success/s)
    {
							print "ISDN connection to $ip ($desc) failed\n";
    }
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top