I have a piece of code that takes the output from a ssh command and puts it into an array. I could put it into a sting also and for this case I use both an array and a string. After I capture the output, I split the array or string on a \n and put the output of this into an array or another string. Next, run a foreach on the array or string and find the lines I need. There has to be a better way, if someone could give me some suggestions, I would appreciate it.
### start of code where I capture the command output $exp->send("show port\n"); $exp->expect(15, [ '# ', sub { my $self = shift; @port = $self->exp_before; }], ); foreach my $line (@port) { my @PORTS = split('\n', $line); foreach my $str (@PORTS){ if ($str =~ /^\d/) { $PORT_NO = (split /\s+/, $str) [0]; $exp->send("show port $PORT_NO detail\n"); $exp->expect(15, [ '# ', sub { my $self = shift; ### Here I use a string to cature the output $output_str = $self->exp_before; }], ); foreach my $string (split('\n', $output_str)){ chomp $string; if ($string =~ /Part Number/) { $model = (split /\s+/, $string) [3]; print "Node: $NODE_NAME,Port: $PORT_NO,Part: $mo +del\n"; } } } } }
In reply to array and string split by numele
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |