472,952 Members | 2,205 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,952 software developers and data experts.

Parse output

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
1 1356
nithinpes
410 Expert 256MB
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

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

Similar topics

6
by: chuck amadi | last post by:
Hi , Im trying to parse a specific users mailbox (testwwws) and output the body of the messages to a file ,that file will then be loaded into a PostGresql DB at some point . I have read the...
1
by: chuck amadi | last post by:
By the way list is there a better way than using the readlines() to > > >parse the mail data into a file , because Im using > > >email.message_from_file it returns > > >all the data i.e reads one...
2
by: praba kar | last post by:
Dear all, I want to parse the system functions output but I couldn't do it. Kindly assist me in this task. eg) bytesused = os.system('du -sh /Users/enmail') if I print this bytesused...
4
by: Liang | last post by:
Hi all, I want to diff two files or two versions of one file, and parse the output to find a summary of how many lines of replacement/addition/deletion in the two files. Known from...
13
by: temp | last post by:
Hi all, I know this is easy for you guys but I am not a VB developer. My boss just wanted me to generate a mapping of all the queries in our Access DB. So I managed to create some subroutines to...
19
by: Johnny Google | last post by:
Here is an example of the type of data from a file I will have: Apple,4322,3435,4653,6543,4652 Banana,6934,5423,6753,6531 Carrot,3454,4534,3434,1111,9120,5453 Cheese,4411,5522,6622,6641 The...
10
by: Michael B. Trausch | last post by:
Alright... I am attempting to find a way to parse ANSI text from a telnet application. However, I am experiencing a bit of trouble. What I want to do is have all ANSI sequences _removed_ from...
4
by: yinglcs | last post by:
Hi, I use os.system() to execute a system command in python. Can you please tell me how can I parse (in python) the output of the os.system() ? Thank you.
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
14
by: dbldeegd | last post by:
My Java Script executes fine on an test HTML page, but on the required page which is php results in an error. the page The script drops in message box when the page is loaded since the script...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.