Parse output

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • flynnbg
    New Member
    • Sep 2008
    • 2

    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.
    Code:
    foreach $any (@highway) {
            if ($any =~ "CPU") {
                    $cpu = $any ;
            } elsif ($any =~ "MEM") {
                    $mem = $any ;
            } elsif ($any =~ "HOSTNAME") {
                    $rvr_host = $any ;
            } else {
                    until ($any eq $dup) {
                            push (@config, $any) ;
                    }
            push (@live, $any) ;
            }
    }
    any pointers would be appreciated.
    Last edited by numberwhun; Sep 30 '08, 11:05 AM. Reason: Please use code tags
  • nithinpes
    Recognized Expert Contributor
    • Dec 2007
    • 410

    #2
    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:

    Code:
    foreach $any (@highway) { 
            if ($any =~ "CPU") { 
                    $cpu = $any ; 
            } elsif ($any =~ "MEM") { 
                    $mem = $any ; 
            } elsif ($any =~ "HOSTNAME") { 
                    $rvr_host = $any ; 
            } else { 
               push @live,$any unless($any=~/Dup/) ; 
               if($any=~/Dup/) {@config=@live; @live=();}
            } 
    }

    Comment

    Working...