By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,178 Members | 987 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,178 IT Pros & Developers. It's quick & easy.

Parse output

P: 2
Hi first posting here.

I'm using perl to connect via port to a remote box which then runs a command which appears in a array from the call box. I'm parsing the output, but seem to be having a problem with syntax. I wonder if someone could help.

Output in array

HOSTNAME xxxxx
CPU 1.2
MEM 53M
ARB-MDATA-1
ARB-MDATA-2
MTL-MDATA-1
Dup
ARB-MDATA-1
ARB-MDATA-2
MTL-MDATA-1
NYC-MDATA-5

from my script I can get everything working apart from reading "Dup" as the delimiter.
Expand|Select|Wrap|Line Numbers
  1. foreach $any (@highway) {
  2.         if ($any =~ "CPU") {
  3.                 $cpu = $any ;
  4.         } elsif ($any =~ "MEM") {
  5.                 $mem = $any ;
  6.         } elsif ($any =~ "HOSTNAME") {
  7.                 $rvr_host = $any ;
  8.         } else {
  9.                 until ($any eq $dup) {
  10.                         push (@config, $any) ;
  11.                 }
  12.         push (@live, $any) ;
  13.         }
  14. }
  15.  
any pointers would be appreciated.
Sep 30 '08 #1
Share this Question
Share on Google+
1 Reply


nithinpes
Expert 100+
P: 410
The until loop inside foreach loop will result in infinite loop as for each iteration the $any will be having a single value, using until loop without any modification of the value will result in infinite loop.

If I am understanding it right, you are trying to push all lines before 'Dup' to @config and that after it to @live (after taking out other $cpu, $mem & $rvr_host). Here is one way of doing it:

Expand|Select|Wrap|Line Numbers
  1. foreach $any (@highway) { 
  2.         if ($any =~ "CPU") { 
  3.                 $cpu = $any ; 
  4.         } elsif ($any =~ "MEM") { 
  5.                 $mem = $any ; 
  6.         } elsif ($any =~ "HOSTNAME") { 
  7.                 $rvr_host = $any ; 
  8.         } else { 
  9.            push @live,$any unless($any=~/Dup/) ; 
  10.            if($any=~/Dup/) {@config=@live; @live=();}
  11.         } 
  12.  
Sep 30 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.