in reply to array and string split

To assist you better, could you show some example output of the two commands show port and show port $PORT_NO detail that you are trying to parse?* Also, I see you're splitting on '\n', which is a literal backslash followed by a lower case n, is that intentional? If you meant to split on a line break, you should use "\n" (in double quotes, because those interpolate, single quotes don't).

* Perhaps the output of use Data::Dumper; $Data::Dumper::Useqq=1; print Dumper(\@port); and in the loop print Dumper($output_str);

Replies are listed 'Best First'.
Re^2: array and string split
by numele (Sexton) on Jan 27, 2015 at 00:32 UTC

    I should have mentioned, my approach works very well, just wanted to see if there is a better method.

      There might be, maybe with a regex, but we'd still have to see the string the regex would be operating on...

      On the other hand, if it works well (which usually also means it's well tested and the performance is acceptable), don't touch a running system :-)

        There are many reasons why a programmer should "touch a working system." (Of course he should keep a backup. He may need it.) In this case, the OP is trying to improve his perl skills.

        A "working system" may pass its functional tests, but fail any test for maintainability. These should be treated the same as any other failure. The sooner they are fixed, the lower we can expect the total life-cycle cost to be.

        Bill