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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array problem

Status
Not open for further replies.

krock923

IS-IT--Management
May 24, 2006
4
US
Hi there. I'm working on a program using the Expect module that connects to 3com switches and sucks out vlan information. I'm having a problem with a specific code block, related to the parsing of the returned data.

Here's a sample of the data, first.

Code:
1               none
1               none
1               1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
                17, 18, 19, 20, 21, 22, 23, 24
1               none

It's in an array with each line being one element. I'm trying to go through this array and look to see if a line that doesn't have the unit number at the front of it is right after a unit line with the unit mumber at the front, merge the elements together. However, it's not working the way I expect it to. Here's the code:

Code:
$size=@PortsArray;
$counter=0;

my $final;

while ($counter < $size)
{
       if ($PortsArray[$counter] !~ m/^$UnitNumber/)
       {
               $PortsArray[$counter] =~ s/^\s+//;
               my $prev = $counter - 1;
               my $otherNewString = "$PortsArray[$counter]";
               my $newString = "$PortsArray[$prev]";
               $final = "$newString $otherNewString";
               $PortsArray[$prev]="$otherNewString $newString";
               $PortsArray[$counter]="";
       }
$counter++;
}


Any help with this would be very much appreciated. I've been banging my head against the wall with it all day.
 
It's supposed to be

$PortsArray[$prev]="$otherNewString $final";

All those newstring, otherstring stuff ate just attempts at debugging.
 
How about something like this:
Code:
my @parsed;

while (<DATA>) {
    my @temp = split /\s{2,}/, $_;
    if ($temp[0] eq "") {
        $parsed[-1] .= " $temp[1]";
    } else {
        push @parsed, $_;
    }
}

__DATA__
1               none
1               none
1               1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
                17, 18, 19, 20, 21, 22, 23, 24
1               none
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top